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