我想尝试 AWS Lambda 的自定义 C++ 运行时并使用本地测试SAM https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html。不幸的是我得到了错误Runtime exited without providing a reason
(比较下面的错误详细信息)。如何使用 SAM 在本地运行 C++ Lambda 函数?
方法:
我正在按照中描述的确切步骤进行操作官方 C++ 简介博客 https://aws.amazon.com/blogs/compute/introducing-the-c-lambda-runtime/,直到“创建您的 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
Invoke:
我在跑步sam local start-api --debug
in the debug
文件夹。
我通过以下方式调用该函数127.0.0.1:3000/hello
铬合金。
Error:
调用 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 的机器上进行远程构建(我希望情况并非如此)
我可以使用云形成包 https://docs.aws.amazon.com/cli/latest/reference/cloudformation/package.html正如这里推荐的堆栈溢出 https://stackoverflow.com/questions/54699866/aws-lambda-c-runtime-in-sam。我想避免这种情况,因为我只想在本地进行测试。