AWS Lambda - serverless computation service in AWS.
Here we have an example how to deploy “hello-world” AWS Lambda with a simple Burr application. This example is based on the official instruction: https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-instructions
Build Docker image for deploy in AWS ECR
docker build --platform linux/amd64 -t aws-lambda-burr .
Local tests:
Run Docker container:
docker run -p 9000:8080 aws-lambda-burr
Send test request to check if Docker container executes it correctly:
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"body": {"number":3}}'
Ensure the AWS account number (111122223333) is correctly replaced with yours:
Authenticate Docker to Amazon ECR:
Retrieve an authentication token to authenticate your Docker client to your Amazon Elastic Container Registry (ECR):
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 111122223333.dkr.ecr.us-east-1.amazonaws.com
Create the ECR Repository:
aws ecr create-repository --repository-name aws-lambda-burr \ --region us-east-1 \ --image-scanning-configuration scanOnPush=true \ --image-tag-mutability MUTABLE
Ensure the AWS account number (111122223333) is correctly replaced with yours:
docker tag aws-lambda-burr 111122223333.dkr.ecr.us-east-1.amazonaws.com/aws-lambda-burr:latest docker push 111122223333.dkr.ecr.us-east-1.amazonaws.com/aws-lambda-burr:latest
Example of creating an AWS Role for Lambda execution:
aws iam create-role \ --role-name lambda-ex \ --assume-role-policy-document '{"Version": "2012-10-17","Statement": [{ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}'
Ensure the AWS account number (111122223333) is correctly replaced with yours:
aws lambda create-function \ --function-name aws-lambda-burr \ --package-type Image \ --code ImageUri=111122223333.dkr.ecr.us-east-1.amazonaws.com/aws-lambda-burr:latest \ --role arn:aws:iam::111122223333:role/lambda-ex
aws lambda invoke \ --function-name aws-lambda-burr \ --cli-binary-format raw-in-base64-out \ --payload '{"body": {"number": 5}}' \ response.json