我想尝试 AWS Lambda 的自定义 C++ 运行时并使用SAM在本地对其进行测试。不幸的是,我收到了错误Runtime exited without providing a reason
(比较下面的错误详细信息)。如何使用 SAM 在本地运行 C++ Lambda 函数?
方法:
我正在遵循官方 C++ 简介博客中描述的确切步骤,直到“创建您的 C++ 函数”的最后一步。博客的其余部分是关于在 Lambda 上部署函数(我不想这样做,因为我想在本地使用 SAM)。
为了使用 SAM,我template.yaml
在构建目录中添加了一个。现在的结构build dir
如下所示:
├── CMakeCache.txt
├── CMakeFiles
| |...
├── cmake_install.cmake
├── hello
├── hello.zip
├── Makefile
└── template.yaml
6 directories, 37 files
这是template.yaml
构建目录中的内容:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
cpp hello world
Globals: # default settings across all resources if nothing else is specified
Function:
Timeout: 15
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello.zip # relative location or S3 key
Handler: hello # function to handle call? Why is this hello and not main?
Runtime: provided
Events:
HelloWorld: # the name of the event
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: get
Outputs:
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: "Hello World Lambda Function ARN"
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: "Implicit IAM Role created for Hello World function"
Value: !GetAtt HelloWorldFunctionRole.Arn
调用:
我sam local start-api --debug
在debug
文件夹中运行。我通过127.0.0.1:3000/hello
在 chrome 中调用该函数。
错误:
调用 URL 产生的消息中的一些详细信息:
...
Invoking hello (provided)
Decompressing /home/path/to/folder/test_cpp_local/aws-lambda-cpp/build/hello_cpp/build/hello.zip
Fetching lambci/lambda:provided Docker container image......
Mounting /tmp/tmpm9djt4mb as /var/task:ro,delegated inside runtime container
/var/task/bin/hello: error while loading shared libraries: /var/task/lib/libc.so.6: file too short
START RequestId: 3435a342-d86d-1a59-df1a-10167070cd22 Version: $LATEST
END RequestId: 3435a342-d86d-1a59-df1a-10167070cd22
REPORT RequestId: 3435a342-d86d-1a59-df1a-10167070cd22 Init Duration: 29.71 ms Duration: 0.00 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 6 MB
{
"errorType": "Runtime.ExitError",
"errorMessage": "RequestId: 3435a342-d86d-1a59-df1a-10167070cd22 Error: Runtime exited without providing a reason"
}
Function returned an invalid response (must include one of: body, headers, multiValueHeaders or statusCode in the response object
...
我的系统:
我正在使用 cmake 3.5.1、g++ 4.5.0、gcc 4.5.0 在 Ubuntu 16.04 上构建
如何解决这个问题的想法:
我必须以某种方式在使用 AWS Linux 的机器上构建远程(我希望不是这种情况)
我可以使用这里推荐的CloudFormationPackage stackoverflow。我想避免这种情况,因为我只想在本地进行测试。