auto determine Lambda Layer ARN

0

We can add AWS provided layers to lambda via console. below is the line for cloudformation

Layers:
        - arn:aws:lambda:us-east-2:590474943231:layer:AWS-Parameters-and-Secrets-Lambda-Extension:4

where we can directly put ARN.

but how to determine automatically based on name and version? so we we can have it dynamically for different region as well.

tried same to determine using terraform as well but no luck

 data "aws_lambda_layer_version" "existing_security_layer" {
   layer_name = "AWS-Parameters-and-Secrets-Lambda-Extension"
  version= 4
}
1 Answer
0

The ARN for a Lambda layers is constructed as follows. Using this information you can construct the right ARN to put into things like CloudFormation and CDK.

arn:PARTITION:REGION:ACCOUNT:layer:LAMBDA-LAYER-NAME:VERSION

  • If you're operating in the AWS commercial regions (which is everything except our China regions and GovCloud) then REGION will be "aws".
  • REGION is the region name that the Lambda Layer is deployed in.
  • ACCOUNT is the account number that you're operating in.
  • LAMBDA_LAYER_NAME is the name of the layer.
  • VERSION is the version that you want to reference.

You can find more information about how ARNs are constructed here: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html

You can also call the Lambda service using the ListLayers API to look for the current version of the Lambda Layer.

profile pictureAWS
EXPERT
answered a year ago
  • unfortunately, that did not work.

    aws provided lambda layers is different in different region and it's different from logged-in account.

    if we want to create a lambda and add a layer using terraform or cloudformation without knowing the layer ARN beforehand, how to do that?

    I can pass the lambda layer name and version. also below commands is giving an empty list

    aws lambda list-layers \
        --compatible-runtime python3.7
    

    Output

    [ ]
    
  • At this time, there isn't an API to get a list of AWS-curated Lambda Layers.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions