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개 답변
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
전문가
답변함 일 년 전
  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인