🐾Developing Lambda - Testing containers🐾
❓Testing can be cumbersome when you have to continuously push images to ECR and deploy your Lambdas. It consumes a significant amount of time.
✅ With AWS Lambda Python Runtime Interface Client we have ability to test Lambda containers locally.
Run the following three commands to do it:
1️⃣ Download and install client to your local machine.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
2️⃣ Run your function container with docker command. Replace myfunction:latest with name of your image and app.handler with file and function names.docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \ --entrypoint /aws-lambda/aws-lambda-rie \ myfunction:latest \ /usr/local/bin/python -m awslambdaric app.handler
3️⃣ Post an event to test the function. Replace json with input your function expects. curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"file": "test"}'
🎁 To experiment with Lambda-like environment you can use the following Docker image: docker run -it --rm amazonlinux bash
Documentation: https://docs.aws.amazon.com/lambda/latest/dg/images-test.html
If you like this post, you can share APAWS newsletter with friends: