tmclaugh / aws-cfn-lambda-updater

AWS Lambda function to update Lambda functions via CloudFormation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aws-cfn-lambda-updater Build Status

Lambda function to update other Lambda function when called via CloudFormation.

This repository contains two Lambda functions along with CloudFormation templates for each function.

Deployment

Deploying Both stacks can be done by clicking on "Launch Stack" below.

  • aws-cfn-lambda-updater: Launch CloudFormation Stack
  • aws-cfn-lambda-updater-example-lambda: Launch CloudFormation Stack

Usage

To use aws-cfn-lambda-updater to update another Lambda function that is deployed via CloudFormation, add a resource similar to the following to your CloudFormation template. You’ll need to add parameters for LambdaName and S3Bucket.

"LambdaInvokeUpdater": {
  "Type": "Custom::LambdaUpdaterInvoke",
  "Properties": {
    "ServiceToken":{
      "Fn::ImportValue": {
        "Fn::Sub": "aws-cfn-lambda-updater-LambdaFunctionArn"
      }
    },
    "FunctionName": {
      "Ref": "LambdaName"
    },
    "S3Bucket": {
      "Ref": "S3Bucket"
    },
    "S3Key": {
      "Fn::Sub": "${LambdaName}.zip"
    }
  }
}

To ensure that the LambdaInvokeUpdater resource requires an update on each version, add a command like the following to your build process.

$ python -c "import json, sys; cfn=json.load(sys.stdin); cfn['Resources']['LambdaInvokeUpdater']['Properties']['CodeSha256'] = '$(openssl dgst -binary -sha256 dist/aws-cfn-lambda-updater.zip | openssl base64)'; json.dump(cfn, sys.stdout, indent=2)" < dist/aws-cfn-lambda-updater-example-lambda.json > dist/aws-cfn-lambda-updater-example-lambda.json.new; mv dist/aws-cfn-lambda-updater-example-lambda.json{.new,}

See this repository’s .travis.yml for an example in practice.

About

AWS Lambda function to update Lambda functions via CloudFormation.


Languages

Language:Python 100.0%