I would like to try the custom C++ runtime for AWS Lambda and testing it locally using SAM. Unfortunately I get the error Runtime exited without providing a reason
(compare error details below). How can I run C++ Lambda functions locally with SAM?
Approach:
I am following the exact steps described in official C++ Introduction blog, up to the last step of "Create your C++ function". The rest of the blog is about deploying the function on Lambda (which I DO NOT want to do, since I would like to use SAM locally).
In order to use SAM, I am putting a template.yaml
in the build dir. The structure of the build dir
now looks like this:
├── CMakeCache.txt
├── CMakeFiles
| |...
├── cmake_install.cmake
├── hello
├── hello.zip
├── Makefile
└── template.yaml
6 directories, 37 files
This is the content of the template.yaml
in the build dir:
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:
I am running sam local start-api --debug
in the debug
folder.
I am invoking the function by going to 127.0.0.1:3000/hello
in chrome.
Error:
Some details from the message that results from invoking the 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
...
My System:
I am building on a Ubuntu 16.04 using cmake 3.5.1, g++ 4.5.0, gcc 4.5.0
Ideas how to solve this:
I somehow have to build remote on a machine that uses AWS Linux (I hope that this is not the case)
I could use the CloudFormationPackage as recommended here stackoverflow. I would like to avoid this, since I would like to test locally only.