aws / serverless-application-model

The AWS Serverless Application Model (AWS SAM) transform is a AWS CloudFormation macro that transforms SAM templates into CloudFormation templates.
https://aws.amazon.com/serverless/sam
Apache License 2.0
9.29k stars 2.37k forks source link

Bug: No new Lambda Versions are deployed with Lambda configurations changes #3622

Closed mriccia closed 9 hours ago

mriccia commented 1 month ago

Description:

When there is a SAM template with a Lambda function property AutoPublishAlias, I expect that changes to the Lambda function will publish a new Lambda Version. However, it seems that a new Version is not published in certain scenarios, if there are no code changes. For example: changes to the Logging configuration, and changes to the description.

Steps to reproduce:

  1. sam build && sam deploy a SAM project with a Lambda function with the AutoPublishAlias set
  2. Make changes to the Logging configuration
  3. sam build && sam deploy the project again

Observed result:

The Lambda configuration has changed, however there's no new version published

Expected result:

A new Lambda Version is published and the Alias is updated

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Mac OS
  2. sam --version: SAM CLI, version 1.115.0
  3. AWS region: eu-west-2
sam --info --debug
{ 
  "version": "1.115.0",
  "system": {
    "python": "3.12.3",
    "os": "macOS-14.4.1-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "25.0.3",
    "aws_cdk": "2.139.0 (build 2699ffd)",
    "terraform": "1.4.2"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Add --debug flag to command you are running

lucashuy commented 1 month ago

Hi, thanks for opening this issue. Unfortunately I'm not able to produce the issue following these steps:

1. Initial state

  1. sam init a hello world NodeJS function
  2. modify the function to look something like this:
    Resources:
    HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello-world/
      Handler: app.lambdaHandler
      Runtime: nodejs20.x
      Architectures:
        - x86_64
      Description: "foo1"
      VersionDescription: "bar1"
      AutoPublishAlias: gh7102alias
  3. sam build
  4. sam deploy

This deploys successfully with a Lambda version 1.

2. Adding LoggingConfig and update description

  1. modify the function
    Resources:
    HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello-world/
      Handler: app.lambdaHandler
      Runtime: nodejs20.x
      Architectures:
        - x86_64
      Description: "foo2"
      VersionDescription: "bar2"
      AutoPublishAlias: gh7102alias
      LoggingConfig:
          ApplicationLogLevel: DEBUG
          LogFormat: JSON
          SystemLogLevel: DEBUG
  2. sam build
  3. sam deploy

I can see that the description for the original function's description is updated, along with the version's description. Additionally, a new Lambda version was published with the new logging changes to the original function.

mriccia commented 1 month ago

Hello @lucashuy , thanks for the prompt response. What's triggering the new version deployment in the steps you shared is the VersionDescription. Without VersionDescription I can consistently see the Lambda Configuration being updated, without a new version being published. Please can you test with the following steps?

Initial state

  1. sam init a hello world NodeJS function
  2. modify the function to look something like this:
    Resources:
    HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello-world/
      Handler: app.lambdaHandler
      Runtime: nodejs20.x
      Architectures:
        - x86_64
      Description: "foo1"
      AutoPublishAlias: gh7102alias
  3. sam build
  4. sam deploy

This deploys successfully with a Lambda version 1.

Adding LoggingConfig and update description

  1. modify the function
    Resources:
    HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello-world/
      Handler: app.lambdaHandler
      Runtime: nodejs20.x
      Architectures:
        - x86_64
      Description: "foo2"
      AutoPublishAlias: gh7102alias
      LoggingConfig:
          ApplicationLogLevel: DEBUG
          LogFormat: JSON
          SystemLogLevel: DEBUG
  2. sam build
  3. sam deploy

I can see that the description and logging configuration for the original function are updated, but there isn't a new Lambda Version published.

hawflau commented 1 week ago

@mriccia Could you try using AutoPublishAliasAllProperties? As described in the doc:

Specifies when a new AWS::Lambda::Version is created. When true, a new Lambda version is created when any property in the Lambda function is modified. When false, a new Lambda version is created only when any of the following properties are modified:

  • Environment, MemorySize, or SnapStart.

  • Any change that results in an update to the Code property, such as CodeDict, ImageUri, or InlineCode.

I'm moving this to the SAM Repo as this question fit better under the scope of SAM than SAM CLI.

GavinZZ commented 1 week ago

@mriccia Thanks for reaching out. As Wing has pointed out, please try out AutoPublishAliasAllProperties property.

GavinZZ commented 9 hours ago

Closing this issue as I believe the root cause is identified and AutoPublishAliasAllProperties is the fix for the issue. Feel free to re-open or open a new issue if this doesn't work for you or if you have additional questions.

github-actions[bot] commented 9 hours ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one.