Search code examples
aws-lambdagithub-actionsserverless-framework

Is it possible to deploy serverless framework with container images using GitHub actions


Currently we have a lambda deployment that needs to be in a container due to the size of the python libraries used. It’s deployed from a developer’s machine using the Serverless framework CLI

Separately we deploy other lambdas via serverless using GitHub actions - so the code base is shared.

Is there any way (and I’ve looked but can’t find an answer!) that we can deploy a container image from GitHub?

Or are we better off putting the libraries in a layer container image (deployed as at present) and then moving the code itself to GitHub where it can be viewed centrally?


Solution

  • Yes you can. Just build image with your code and dependencies, push to ECR and then deploy it as a containerized lambda.

    name: Deploy to AWS Lambda
    
    on:
     push:
       branches:
         - main
    
    jobs:
     deploy:
      runs-on: ubuntu-latest
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
    
    - name: Login to AWS ECR
      uses: aws-actions/amazon-ecr-login@v1
    
    - name: Build Docker image
      uses: docker/build-push-action@v2
      with:
        context: .
        push: true
        tags: your-registry-url/your-image-name:latest
    
    - name: Deploy to AWS Lambda
      uses: serverless/github-action@v1
      with:
        args: deploy
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}