3

I'm following the instructions to locally test lambda container https://docs.aws.amazon.com/lambda/latest/dg/images-test.html

but I am unable to do so.

I've created a sample project to reproduce it https://gitlab.com/sunnyatticsoftware/sandbox/lambda-dotnet5-webapi (see the README for step by step on its generation)

Basically I am using an Amazon dotnet template that generates an AWS Lambda function as a .NET 5 web api using containers.

It's all good with the project. The Dockerfile is described as

FROM public.ecr.aws/lambda/dotnet:5.0
WORKDIR /var/task
COPY "bin/Release/net5.0/publish"  .

Now I want to test it locally using the Amazon Lambda Runtime Interface Emulator (RIE) and these are the steps I follow:

  1. Build project with dotnet build -c Release
  2. Publish artifacts with dotnet publish -c Release
  3. Build docker image with docker build -t lambda-dotnet .
  4. Download the RIE with
    mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && chmod +x ~/.aws-lambda-rie/aws-lambda-rie
    
    I can see the emulator downloaded properly
    ls -la ~/.aws-lambda-rie/aws-lambda-rie
    -rw-r--r-- 1 diego.martin 1049089 8155136 Feb 22 14:32 /c/Users/diego.martin/.aws-lambda-rie/aws-lambda-rie
    
  5. Run the emulator passing the lambda image
    docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 --entrypoint /aws-lambda/aws-lambda-rie lambda-dotnet:latest
    

Here is when I get the error

12997dddc6e50aca3020527be30a1479eee9ceef412ab5009b99e9eb8cf1fa67
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "C:/Users/diego.martin/AppData/Local/Programs/Git/aws-lambda/aws-lambda-rie": stat C:/Users/diego.martin/AppData/Local/Programs/Git/aws-lambda/aws-lambda-rie: no such file or directory: unknown.

What am I missing? I am not specifying any entrypoint because I don't have any.

PS: The last step would be to send some lambda event to my container's function with

curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
1

1 Answer 1

5

The lambda docker images for dotnet already include the RIE, so it's enough with the following (see repo with further details):

To build image

docker build -t lambda-dotnet:latest .

To run it

docker run -p 9000:8080 lambda-dotnet "LambdaDotNet5::LambdaDotNet5.LambdaEntryPoint::FunctionHandlerAsync"

And then to test it, I can use CURL from a different terminal

curl -vX POST http://localhost:9000/2015-03-31/functions/function/invocations -d @test_request.json --header "Content-Type: application/json"

and in the test_request.json file I can have the json for the event I want to send to the lambda.

Sign up to request clarification or add additional context in comments.

1 Comment

Or for windows Invoke-WebRequest -Uri http://localhost:9000/2015-03-31/functions/function/invocations -Headers @{ "Content-Type" = "application/json" } -Method Post -InFile test_request.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.