How to Build and Push a Docker Lambda Docker Image and Update a Remote Function
2 min readOct 22, 2023
This tutorial explains how to build a Docker image for an AWS Lambda function written in Docker, push it to an AWS ECR repository, and update the remote Lambda function with the new image.
Prerequisites
- Docker installed locally
- AWS CLI installed and configured with credentials to access AWS ECR and Lambda
- Lambda function already created in AWS, with name
my-lambda
- Assume that the target region is us-east-1
Steps
- Authenticate Docker with ECR using aws ecr get-login-password
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin XXXXXX.dkr.ecr.us-east-1.amazonaws.com
This gets a temporary password and uses it to authenticate Docker with the ECR registry.
2. Build the Docker image
docker build --platform linux/amd64 -t my-lambda-container:$version .
This builds the Docker image based on the Dockerfile in the current directory, tagging it with my-lambda-container:$version. The — platform linux/amd64 flag specifies the architecture.
- $version: Your image tag