How to pass lambda layer arn to a lambda in cloudformation ?

0

I have cloudformation template , shown below . I am creating a serverless lambda and trying to pass a lambda arn , but when this template is deployed , i get an error that it is not a valid arn. I've deployed other cloudformation templates passing similar ARN , which works, but I'm not sure why the lambda arn is different or special?

AWSTemplateFormationVersion: 
.....

Parameters:
   lambdaArn:
     Type: String 
     Default:  arn:aws:lambda:us-east-1:6666666666666:layer:myLayer:1

Resources:
  mylambda:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: testlayer
      ....
      Layers:
      - !Ref lambdaArn

asked a year ago1524 views
5 Answers
1

This might not fix it but I'd try putting quotes around the ARN.

EXPERT
answered a year ago
0

Difficult to find any issues in the ARN, however it might be malformed YAML file in this case. I can see an extra WHITESPACE in here: "Default: arn:aws:lambda:us-east-1:6666666666666:layer:myLayer:1". Can you try removing that just to rule it out?

answered a year ago
  • tried it without space as well.

0

That arn is only the default value for the parameter, you're not overriding it are you, e.g. with a space?

EXPERT
answered a year ago
0

There you go a full example:

  AppLambda:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: !Sub ${EnvName}-${AWS::Region}-lambda-function-app
      Description: !Sub APP API lambda function version ${AppLambdaVersion}
      Code:
        S3Bucket: !Ref SpecBucketName
        S3Key: !Join ['', [ 'templates/lambda/app/', !Ref ContactLambdaVersion , '/zip/', !Ref EnvName , '-' , !Ref AWS::Region , '-', !Ref CommitSha, '-lambda-function-app.zip' ] ]
      Handler: index.lambda_handler
      Role:
        Fn::GetAtt:
          - LambdaAppCommonRole
          - Arn
      Runtime: nodejs12.x
      TracingConfig:
        Mode: Active
      Timeout: 180
      Layers:
        - !Join [ '', [ 'arn:aws:lambda:', !Ref AWS::Region , ':' , !Ref AWS::AccountId , ':layer:lib-layer:24' ] ]
      Environment:
        Variables:
          APP_VAR: myvalue
      Tags:
        - Key: Name
          Value: !Ref AWS::StackName
        - Key: Project
          Value: !Ref ProjectName
        - Key: Environment
          Value: !Ref EnvName
profile picture
answered a year ago
0

The following works for me with managed AWS layers, e.g.

      Layers:
        - arn:aws:lambda:eu-north-1:666666666666:layer:AWSSDKPandas-Python311:4

That would suggest it is caused by myLayer being unknown?

answered 3 months ago

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