/aws-lambda-docker-node

Continuous Integration and Continuous Deployment setup for AWS Lambda functions with Docker images using GitHub Actions.

Primary LanguageMakefile

Example CI/CD for AWS Lambda w/ Docker

A Continuous Integration and Continuous Deployment setup for AWS Lambda functions with Docker images using GitHub Actions. Together with Semantic Releases and Conventional Commits, you can focus on writing your code. Automation takes care everything else.

Configuration

You need to configure these environment variables as GitHub secrets:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_REGION
  • CUSTOM_GITHUB_TOKEN

Workflows

Everything runs with GitHub Actions; a full cycle includes three stages:

Read more about Event-Driven Delivery.

Semantic Version

on: push: branches: ["main"]

Every push on main branch triggers the GitHub Action in version.yml to create a new GitHub Release based on Conventional Commits.

Deployment

on: release: types: ['created']

Every new GitHub Release triggers the GitHub Action in deployment.yml to build the Docker image and upload the tagged image to the Amazon Elastic Container Registry. Afterwards, a new GitHub Deployment is created.

Release

on: deployment_status

Using GitHub Deployments, the GitHub Action in release.yml updates the AWS Lambda function to use the updated Docker image.

Infrastructure

First, create a new repository using the Amazon Elastic Container Registry. The CloudFormation template in infrastructure.yml includes all needed resources.

# Configure Amazon Elastic Container Registry

$ > AWS_REGION=eu-central-1 \
    make deploy-infrastructure

Notes

Per default, GitHub configures an access token for every action run. When using the default token, an action cannot trigger any other actions. Therefore, a custom GitHub Token is needed for using the GitHub API.