Skip to content

GitHub action that updates the given AWS Lambda.

License

Notifications You must be signed in to change notification settings

kazimanzurrashid/aws-lambda-update-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

AWS Lambda update action

GitHub GitHub release (latest by date) GitHub Workflow Status

This action updates a given lambda. It is very lightweight comparing to others, it uses the latest AWS Node SDK 3 which only pulls lambda client to update the lambda code.

Usage

minimum

uses: kazimanzurrashid/[email protected]
with:
  zip-file: './dist/my_lambda.zip'

complete

uses: kazimanzurrashid/[email protected]
with:
  zip-file: './dist/my_lambda.zip'
  lambda-name: 'your_lambda'
  AWS_REGION: ${{ secrets.AWS_REGION }}
  AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
  AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} 

AWS Permission

The AWS Account needs to have the "lambda:UpdateFunctionCode" permission.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["lambda:UpdateFunctionCode"],
      "Resource": "*" // Don't use for production, change it to only your lambda name
    }
  ]
}

Inputs

zip-file

Required. The zip location, this is the only required argument of this action.

lambda-name

Optional. If not specified. it takes the zip file base name as lambda name. (e.g. if the zip file is my_lambda.zip it would update my_lambda lambda)

AWS_REGION

Optional, if not specified fallbacks to environment variable.

AWS_ACCESS_KEY_ID

Optional, if not specified fallbacks to environment variable.

AWS_SECRET_ACCESS_KEY

Optional, if not specified fallbacks to environment variable.

AWS_SESSION_TOKEN

Optional, if not specified fallbacks to environment variable.

Outputs

N/A

Examples

Node.js Lambda

name: API
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Node.js setup
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Build
        run: |
          npm ci
          npm run pack
          cd dist && zip -r -9 api.zip *

      - name: Update
        uses: kazimanzurrashid/[email protected]
        with:
          zip-file: dist/api.zip
        env:
          AWS_REGION: ${{ secrets.AWS_REGION }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

Go Lambda

name: API
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Go setup
        uses: actions/setup-go@v5
        with:
          go-version: 1.20

      - name: Build
        run: |
          go get -v -t -d ./...
          mkdir dist
          CGO_ENABLED=0 go build -o dist/main
          cd dist && zip -r -9 api.zip *

      - name: Update
        uses: kazimanzurrashid/[email protected]
        with:
          zip-file: dist/api.zip
        env:
          AWS_REGION: ${{ secrets.AWS_REGION }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

.NET Lambda

name: API
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: .NET setup
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 6

      - name: Lambda.Tools install
        run: dotnet tool install -g Amazon.Lambda.Tools

      - name: Build
        run: |
          cd src/Api
          dotnet lambda package -o api.zip

      - name: Update
        uses: kazimanzurrashid/[email protected]
        with:
          zip-file: src/Api/api.zip
        env:
          AWS_REGION: ${{ secrets.AWS_REGION }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

License

This project is distributed under the MIT license.