Search code examples
pythonamazon-web-servicesaws-lambdaaws-cdkaws-lambda-layers

How to retrieve ARN attribute from resource in aws_cdk L1?


I have created a L1 lambda layer with the aws cdk as indicated in the docs. I would like to attach this lambda layer to a lambda function. Documentation on lambda functions says the following about the parameter layer:

layers (Optional[Sequence[str]]) – A list of function layers to add to the function’s execution environment. Specify each layer by its ARN, including the version.

How can I get the ARN of my lambda layer in L1? I tried

cfn_function = lambda_.CfnFunction(self, ..., layers = [cfn_layer_version.get_att(resource.arn)])

Solution

  • You would use cfn_layer_version.ref to get the ARN.

    From Cloudformation docs:

    When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the ARN of the layer version, such as arn:aws:lambda:us-west-2:123456789012:layer:my-layer:1.