Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Lambda function (with alias) doesn't create a new version after its layer is updated, even if AutoPublishAliasAllProperties is set to true #3648

Open
paulhcsun opened this issue Sep 5, 2024 Discussed in #3612 · 0 comments
Labels
stage/needs-feedback Needs feedback from the community (are you also interested in/experiencing this?)

Comments

@paulhcsun
Copy link
Contributor

Discussed in #3612

Originally posted by zhanzhenzhen May 31, 2024

Description:

If we use alias for a lambda function (for provisioned concurrency, etc), it won't create a new version after its layer is updated, even if AutoPublishAliasAllProperties is set to true. So the alias still points to the old layer version. But the $LATEST version is synced with the new layer version. Am I missing something, or is it a bug?

Steps to reproduce:

  1. Create those 4 files, then sam build, then sam deploy. Visit the output URL.
  2. After initial deployment, replace the string "old layer" with "new layer" in the layer/layer.mjs file. Build and deploy it again. Visit the output URL.

template.yaml:

AWSTemplateFormatVersion: "2010-09-09"

Transform:
  - AWS::Serverless-2016-10-31

Globals:
  Api:
    Cors:
      AllowMethods: "'*'"
      AllowHeaders: "'*'"
      AllowOrigin: "'*'"
  Function:
    Runtime: nodejs20.x
    Architectures:
      - arm64
    MemorySize: 128
    Timeout: 8

Resources:
  Layer:
    Type: AWS::Serverless::LayerVersion
    Properties:
      LayerName: !Sub ${AWS::StackName}-Layer
      CompatibleArchitectures:
        - arm64
      CompatibleRuntimes:
        - nodejs20.x
      ContentUri: layer
      RetentionPolicy: Delete
    Metadata:
      BuildMethod: nodejs20.x
      BuildArchitecture: arm64

  AppFunction:
    Type: AWS::Serverless::Function
    Properties:
      AutoPublishAlias: Main
      AutoPublishAliasAllProperties: true
      CodeUri: lambda
      Handler: app.handler
      Layers:
        - !Ref Layer
      Events:
        Api:
          Type: Api
          Properties:
            Path: /app
            Method: GET

Outputs:
  URL:
    Description: "Test URL"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/app"

lambda/app.mjs:

import layer from "/opt/nodejs/layer.mjs";

export const handler = async (event, context) => {
    const response = {
        statusCode: 200,
        body: JSON.stringify({fnVersion: process.env.AWS_LAMBDA_FUNCTION_VERSION, layer: layer})
    };
    return response;
};

layer/layer.mjs:

export default "old layer";

samconfig.toml:

version = 0.1

[default]
[default.global.parameters]
stack_name = "TestApp"

[default.build.parameters]
cached = true
parallel = true

[default.validate.parameters]
lint = true

[default.deploy.parameters]
capabilities = "CAPABILITY_NAMED_IAM"
confirm_changeset = true
resolve_s3 = true
s3_prefix = "TestApp"
image_repositories = []

[default.package.parameters]
resolve_s3 = true

[default.sync.parameters]
watch = true

[default.local_start_api.parameters]
warm_containers = "EAGER"

[default.local_start_lambda.parameters]
warm_containers = "EAGER"

Observed result:

In step 1, the result is: {"fnVersion":"1","layer":"old layer"}.

In step 2, the result remains the same.

Expected result:

I expect the result in step 2 to be {"fnVersion":"2","layer":"new layer"}.

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

  1. OS: Linux-6.1.90-99.173.amzn2023.x86_64-x86_64-with-glibc2.34
  2. sam --version: 1.114.0
  3. AWS region: us-east-1
@paulhcsun paulhcsun added the stage/needs-feedback Needs feedback from the community (are you also interested in/experiencing this?) label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-feedback Needs feedback from the community (are you also interested in/experiencing this?)
Projects
None yet
Development

No branches or pull requests

1 participant