Skip to content

aws-samples/cloudformation-custom-resource-attach-latest-lambda-layer

Attach Lambda Layer CloudFormation Custom Resource (CFNAttachLambdaLayer)

Purpose

AWS CloudFormation does not support referencing "the latest version" of a layer when creating a Lambda function. This becomes problematic when the layer was created outside of your CloudFormation template.

CFNAttachLambdaLayer allows you to specify a Lambda and the Layer name that will be attached to it. It will attach the latest version of the Layer to the specified Lambda.

Requirements

Deploying CFNAttachLambdaLayer

From the command line, run:

sam build  --use-container
sam deploy  --stack-name cfn-attach-lambda-layer  --capabilities "CAPABILITY_NAMED_IAM" --resolve-s3 

This will deploy an AWS Lambda custom resource that can be called by your CloudFormation template.

Usage

Parameters:
  Nonce:
    Type: String
    Description: Forces custom resource to run everytime CF runs -- pass in a $RANDOM as a parameter

  AttachLayer:
    Type: Custom::LayerAttachment
    Properties:
      LayerName: <Your Layer name>
      LambdaName: <Lambda name or ARN>
      #CloudFormation will not execute the custom resource if no properties are changed.
      #Along with the parameter, this ensures that the resource is called each time CloudFormation runs
      #If using sam deploy, you can specify:
      #  --parameter-overrides Nonce="$(date +%s)" 
      Nonce: !Ref Nonce
      ServiceToken: !ImportValue CFNAttachLambdaLayer

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages