amazon-web-servicesaws-lambdaaws-cloudformationaws-lambda-layers

How to add a AWS public extension to a AWS Lambda cloud formation template?


I want to add the AWS-Parameters-and-Secrets-Lambda-Extension public extension to the CloudFormation template of my AWS Lambda function.

Everything I found so far adds the public extension either by i) the AWS Lambda console or ii) the AWS CLI. The CloudFormation doc itself states that the AWS::Lambda::LayerVersion only allows to create Lambda layers from a ZIP archive. I've also tried to export the CloudFormation template of a function where I've added the extension using the AWS Lambda console, but that doesn't seem to do the trick.

How do I add this extension to CloudFormation?


Solution

  • The layer is part of AWS::Lambda::Function, see the doc here.

    Then the layer ARN depending on the region you want to deploy your lambda. Here is the list based on the region.

    Something like this for eu-west-1:

    Resources:
      Function:
        Type: AWS::Lambda::Function
        Properties:
          Handler: index.handler
          Role: arn:aws:iam::123456789012:role/lambda-role
          Layers:
            - arn:aws:lambda:eu-west-1:015030872274:layer:AWS-Parameters-and-Secrets-Lambda-Extension:4
          Code:
            S3Bucket: my-bucket
            S3Key: function.zip
          Runtime: nodejs12.x
          Timeout: 5
          TracingConfig:
            Mode: Active