boilerplate-lambda-container/notes/docker.md

1.3 KiB

Build Docker Image

Requirements:

  • sam, aws-cli, docker

Docker Container

Push a docker image to the ECR repository.

export AWS_REGION=us-west-1
export AWS_PROFILE=playground
aws configure sso --profile $AWS_PROFILE
export REPOSITORY_URI=$(aws ecr describe-repositories --repository-names hello-world --region $AWS_REGION --profile $AWS_PROFILE | jq -r '.repositories[0].repositoryUri')
aws ecr get-login-password --region $AWS_REGION --profile $AWS_PROFILE | docker login --username AWS --password-stdin $REPOSITORY_URI

Build the docker image and push it to the ECR repository.

docker build -t hello-world .
docker tag hello-world:latest $REPOSITORY_URI:latest
docker push $REPOSITORY_URI:latest

Testing

Test the container image locally.

docker run -p 8000:8000 hello-world:latest

Check it in another terminal tab.

curl http://localhost:8000
docker stop $(docker ps -q)

Cleanup the repo.

aws ecr delete-repository --repository-name hello-world --region $AWS_REGION --profile $AWS_PROFILE --force

Resources