Skip to content

GuillaumeGSicara/aws-lambda-on-docker-demo

Repository files navigation

Repository description

This repo aims to demonstrate the use of AWS lambda function using a Dockerized image. It uses the following tools

  • AWS CLI (MakeFile interaction)
  • An AWS account with sufficient permissions
  • Terraform (IaC)
  • Docker (container)

The repo allows you to choose between a python base image provided by aws public.ecr.aws/lambda/python:3.XX or from a custom image of your choice (See Dockerfile and Dockerfile.custom for each respective options)

🔧 Using MakeFile

⚠️ Don't forget to use a .set-env.sh file in the tf/ folder

the whole infrastructure can be deployed with the following make commands

make create-registry
make deploy-lambda

💣 Without the MakeFile

1. Create the ECR and deploy with terraform

in tf/ecr you will find the terraform configuration to deploy the ecr registry. The config will create an output registry_url that can be reused when deploying the lambda function

2. Build and push the docker image

⏩ refer to the official documentation for more information

First login to the created ECR

docker login --username AWS --password-stdin $REPO_URL

Build & Push the image

docker build --no-cache --platform linux/amd64 -t $REPOSITORY_NAME:latest .; \
docker tag $REPOSITORY_NAME:latest $REPO_URL:latest; \
docker push $$REPO_URL:latest

Where:

  • $REPOSITORY_NAME is the tag (name) of your docker image
  • $REPO_URL is the full url to access your image (<$AWS_ECR_URL/$REPOSITORY_NAME>)

3. Deploy your lambda function

in the tf/lambda folder your will find the information to deploy your lambda function

💁 Terraform will prompt you for registry_url you can fetch the value from 2.

To test

  • Use poetry in the Dockerfile, poetry files have been added if you want to use these in the DockerFile

Identified Issues

  • Lambda function gets a KMS access denied to read from registry from time to time, deployement is not idempotent w.r.t that error

About

This repo aims to demonstrate the use of AWS lambda function using a Dockerized image

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors