DEV Community

Baptiste Lombard
Baptiste Lombard

Posted on

Deploy AWS lambda functions from a monorepo

My Workflow

Deploy your AWS Lambda functions based on the files changed in a monorepo with this Github Action.

I know a lot of you are using the excellent serverless framework that does a lot for you (including CI/CD). But for smaller use case (personnal Lambda functions for example) I found it easier not to use it.
But not using it comes with a cost so I wanted to eliminate this cost and created this action.

Submission Category:

This is an entry for DIY Deployments

Yaml File or Link to Code

GitHub logo blombard / lambda-monorepo

GitHub Action for Deploying AWS Lambda functions in a mono repo

Maintainability Test Coverage

AWS Lambda monorepo

Deploy your AWS Lambda functions based on the files changed in a mono repo with this Github Action.

Prerequisites

Set you AWS credentials in the secrets of your repo:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_REGION

Create a filters.yml file and put it in .github/worklows : .github/worklows/filters.yml

The structure of the file should be :

LambdaFunction1
  - 'LambdaFunction1/**/*'
LambdaFunction2:
  - 'LambdaFunction2/**/*'

Example

on
  push:
    branches:
      - master

jobs:
  deploy:
    name: Deploy to AWS Lambda
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: ${{ secrets.AWS_REGION }}

    - uses: dorny/paths-filter@v2.2.1
      id: filter
      with:
        filters: .github/filters.yml

    - uses: blombard/lambda-monorepo@master
      with:
        lambda-functions: '${{ toJson(steps.filter.outputs) }}'
        zip-params: '*.js *.json src/ node_modules/
Enter fullscreen mode Exit fullscreen mode

If you want to use this action in your workflow here is an example :

Set your AWS credentials in the secrets of your repo:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_REGION

Create a filters.yml file and put it in .github/worklows : .github/worklows/filters.yml

The structure of the file should be :

LambdaFunction1:
  - 'LambdaFunction1/**/*'
LambdaFunction2:
  - 'LambdaFunction2/**/*'
Enter fullscreen mode Exit fullscreen mode

main.yml

on:
  push:
    branches:
      - master

jobs:
  deploy:
    name: Deploy to AWS Lambda 
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: ${{ secrets.AWS_REGION }}

    - uses: dorny/paths-filter@v2.2.1
      id: filter
      with:
        filters: .github/filters.yml

    - uses: blombard/lambda-monorepo@master
      with:
        lambda-functions: '${{ toJson(steps.filter.outputs) }}'
        zip-params: '*.js *.json src/ node_modules/'
        alias-name: 'production'
        layer-name: 'MyLayer'
Enter fullscreen mode Exit fullscreen mode

Additional Resources

This action is based on those Github actions :

Info

This is my first attempt at building a GH action and my first Dev post. Hope you will like it ! And don't hesitate to improve the action if it is useful for you.

Top comments (0)