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

gefragt vor einem Jahr1668 Aufrufe
5 Antworten
1

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

EXPERTE
beantwortet vor einem Jahr
  • tried that , didn't work

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?

beantwortet vor einem Jahr
  • 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?

EXPERTE
beantwortet vor einem Jahr
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
beantwortet vor einem Jahr
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?

beantwortet vor 4 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen