CloudFormation attaching latest layer to Lambda function

Viewed 912

We are using AWS SAM to build and manage an AWS Layer. The same SAM template can easily associate the latest version to lambda functions which are also managed by this template. However, we have other Lambda functions that are managed by other CloudFormation/SAM templates and I don't know latest version (ARN)

This is what we use in the SAM template to associate the layer

Globals:
  Function:
    Layers:
      - !Ref ToolkitLayer

How do I determine the latest version programmatically from a completely different CloudFormation/SAM template? I thought about using an SSM Parameter since it appears CloudFormation can dynamically pull a value. The issue here is that the SSM Parameter also has a version, same issue.

1 Answers

Have you thought about using a Cloudformation macro/transform (both refer to the same thing)?

Using a Cloudformation macro, CF can call a Lambda function with the snippet from your template, and your Lambda function returns the transformed snippet back to CF. In your Lambda function, you would query the latest version of your layer and return that result back to CF.

More details at: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros.html

Related