lundi 22 février 2021

Locally test AWS Lambda container with .NET 5 web api and Lambda RIE

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 '{}'

Aucun commentaire:

Enregistrer un commentaire