Update a Lambda function

Use GitHub Actions to deploy a Lambda Image or S3 bucket update

Instead of deploying your Lambda code in the same pipeline as your infrastructure, you can use CI/CD and GitHub Actions pipelines. With DuploCloud's GitHub Actions integration, you can build and deploy Lambda functions in your AWS account by deploying a Lambda image or by a package uploaded to an S3 bucket.

For general information about deploying serverless applications with GitHub Actions in AWS, reference this blog.

Update a Function Using an Image

Use the following code as a template to update a Lambda container image with GitHub Actions. In this example, the Lambda container image in the dev01 Tenant is updated and redeployed.

You must ensure the following are configured in your environment and your specific situation.

  • The name of lambda is set on the action to your actual lambda

  • Duplocloud context configured correctly

name: Update Lambda

on: 
  workflow_dispatch:
    inputs:
      environment:
        description: The environment to deploy to
        type: environment
        default: dev01
      image:
        description: The full image
        type: string
        required: true

jobs:
  update_service:
    name: Update Lambda
    runs-on: ubuntu-latest
    environment: 
      name: ${{ inputs.environment }}
    env:
      DUPLO_TOKEN: ${{ secrets.DUPLO_TOKEN }}
      DUPLO_HOST: ${{ vars.DUPLO_HOST  }}
      DUPLO_TENANT: ${{ inputs.environment }}
    steps: 
    
    # configures duplocloud and aws
    - name: Cloud CI Setup
      uses: 

    # uses duploctl from above
    - name: Update Lambda
      uses: 
      with:
        type: lambda
        name: mylambda
        image: ${{ inputs.image }}

Update Lambda based on package in Amazon S3

Use the following code as a template to deploy your Lambda functions to an S3 bucket with GitHub Actions. In this example, the Lambda in the dev01 Tenant is updated using an S3 bucket that contains mylambda-v1.zip

You must ensure the following are configured in your environment and your specific situation.

  • Duplocloud context configured correctly

  • S3KEY

  • S3BUCKET

  • LAMBDA_NAME

name: Update Lambda

on: 
  workflow_dispatch:
    inputs:
      environment:
        description: The environment to deploy to
        type: environment
        default: dev01
      s3key:
        description: The key name in the s3 bucket with the version to deploy.
        type: string
        required: false
        default: mylambda-v1.zip

jobs:
  update_service:
    name: Update Lambda
    runs-on: ubuntu-latest
    environment: 
      name: ${{ inputs.environment }}
    env:
      DUPLO_TOKEN: ${{ secrets.DUPLO_TOKEN }}
      DUPLO_HOST: ${{ vars.DUPLO_HOST  }}
      DUPLO_TENANT: ${{ inputs.environment }}
    steps: 
    
    # configures duplocloud and aws
    - name: Cloud CI Setup
      uses: duplocloud/actions/setup@v0.0.3
      
    # we can build the bucket name using context from setup
    - name: Discover True Bucket Name
      env:
        S3BUCKET: mybucket
      run: echo "S3BUCKET=duploservices-${DUPLO_TENANT}-${S3BUCKET}-${AWS_ACCOUNT_ID}" >> $GITHUB_ENV

    # uses duploctl from above to run update lambda function
    - name: Update Lambda from S3
      env:
        LAMBDA_NAME: mylambda
        S3KEY: ${{ inputs.s3key }}
      run: duploctl lambda update_s3 $LAMBDA_NAME $S3BUCKET $S3KEY

References

Last updated

Logo

© DuploCloud, Inc. All rights reserved. DuploCloud trademarks used herein are registered trademarks of DuploCloud and affiliates