Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active April 1, 2021 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpivo/139d2964d50764450a656c3a179f3555 to your computer and use it in GitHub Desktop.
Save rpivo/139d2964d50764450a656c3a179f3555 to your computer and use it in GitHub Desktop.
Creating a GitHub Action Workflow to Update a Lambda Function on Push

Creating a GitHub Action Workflow to Update a Lambda Function on Push

The below workflow will work with a Lambda function written in Node. It's set up to run on every push, but could be updated for other actions.

The workflow is also set up to run on the main branch.

on:
  push:
    branches:
      - main
jobs:
  my_job:
    runs-on: ubuntu-latest
    name: Lambda Update Function Code
    steps:
      - name: Install Dependencies
        run: |
          sudo apt-get update
          sudo apt-get install zip
      - name: Checkout
        uses: actions/checkout@v2
      - name: Build
        uses: actions/setup-node@v1
        with:
          node-version: "15.x"
      - run: npm i
      - run: npm run build --if-present
      - name: Zip
        run: zip -jr lambda.zip ./lambda
      - 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: your-region
      - name: Update Function Code
        run: |
          aws lambda update-function-code \
          --function-name name-of-function \
          --zip-file fileb://lambda.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment