auto update AWS Lambda Application with lambda referencing layer

0

I have a the following template.yml configs referencing a layer.

Resources:
  helloFromLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Layers:
        - arn:aws:lambda:us-east-2:xxxxxxxxx:layer:matchmaking-lobby:63

I have many lambda apps referencing the same layer. Whenever I make changes to this layer I need to manually update each lambda app. I've tried replacing the version number with $LATEST, but that doesn't work. Is there anyway to have the lambdas pull the latest version of the layer?

질문됨 2년 전842회 조회
1개 답변
1
수락된 답변

This behavior isn't possible with CloudFormation. The reason is that referring to $LATEST cannot guarantee a reproducible state for your stack.

Suppose you performed a successful deployment. Then, after the deployment, the latest version of your Lambda Layer changed. Later, you attempt a new deployment that fails. If this happens, CloudFormation will then attempt to revert to the previous known good state. To revert to that known state, CloudFormation needs the specific version number of the Lambda Layer. That's why the specific version number needs to be in the stack template.

Many customers overcome this limitation by including the layer itself in the stack template (via AWS::Lambda::LayerVersion) and making a reference to it. Otherwise, you can do things like put placeholders like $LAYER_VERSION into your CloudFormation YAML template, and substitute the value of the Lambda version into it after you upload it using an external program such as envsubst, before updating the stack with the rendered template.

AWS
전문가
답변함 2년 전
  • I had my RetentionPolicy setting for the layer set to delete originally, and that caused the stack to get stuck because it couldn't reproduce it's previous state like you were talking about. I'll look into merging these separate lambda applications into one big application or maybe writing some sort of aws cli script that would increment the version number across the different lambda projects or just getting rid of the layer and moving the logic to another lambda instead.

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

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

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

관련 콘텐츠