A simple AWS Lambda function written in Go. This document describes how to deploy the function code to an AWS Lambda using Docker and AWS Elastic Container Registry (ECR).
- AWS CLI installed and setup,
- Go installed,
- Docker installed.
docker build --platform linux/amd64 -t <AWS_ECR_REPOSITORY_URI>:latest .- Replace
<AWS_ECR_REPOSITORY_URI>with your registry URI, like111122223333.dkr.ecr.us-east-1.amazonaws.com/repository-name. If you don't have a repository yet, see how to create a new repository.
aws ecr get-login-password --region <AWS_REGION> | docker login --username AWS --password-stdin <AWS_ECR_REGISTRY_URI>- Replace
<AWS_REGION>with a target AWS region, likeus-east-1, - Replace
<AWS_ECR_REGISTRY_URI>with your registry URI, like111122223333.dkr.ecr.us-east-1.amazonaws.com.
docker push <AWS_ECR_REPOSITORY_URI>:latestaws lambda create-function \
--function-name <NAME> \
--package-type Image \
--code ImageUri=<AWS_ECR_REPOSITORY_URI>:latest \
--role <AWS_LAMBDA_EXECUTION_ROLE_ARN>- Replace
<NAME>with a function name, - Replace
<AWS_ECR_REPOSITORY_URI>with your repository URI, like111122223333.dkr.ecr.us-east-1.amazonaws.com/repository-name, - Replace
<AWS_LAMBDA_EXECUTION_ROLE_ARN>with ARN of the Lambda execution role (see how to create an execution role).
aws lambda invoke \
--function-name <NAME> \
--payload '{ "Name": "New event" }' \
--cli-binary-format raw-in-base64-out \
response.json- Replace
<NAME>with a function name.
aws lambda update-function-code \
--function-name <NAME> \
--image-uri <AWS_ECR_REPOSITORY_URI>:latest- Replace
<NAME>with a function name, - Replace
<AWS_ECR_REPOSITORY_URI>with your repository URI, like111122223333.dkr.ecr.us-east-1.amazonaws.com/repository-name.