Repository: aws/serverless-application-model

Issue #1640: Change in Ref'd Parameter Values do not trigger Function Alias update via AutoPublishAlias
Created: 2020-07-01T08:01:44Z
Description:
The auto generation of Logical Resource Ids for AWS::Lambda::Version resources created do not take into account the Value of Parameters Ref'd within the Environment Variables block, but rather the Ref block configuration itself (e.g. {"Environment":{"Variables":{"MyEnv":"MyNewValue"}}}. The end result being that a new Version is not created and the AutoPublishAlias feature does not update the alias for the function to the new version that is created, and only the unqualified function version has its configuration updated.
The example below is shortened, but once DeploymentPreferences are introduced this can result in very unexpected behaviour whereby you think your code is updated to new configuration, but all existing usage of the alias will not be invoking the newly configured function. The only solution outside of this would be to simply no longer use Environment Variables for passing through parameterised configuration, but rather use SSM or AppConfig and write code to utilise these instead from within the Lambda implementation, or to increment or add another hardcoded value within every variable block to force an update.
Environment variables are simply not usable for passing through parameterised configuration (that's expected to be able to change) to lambdas when using AutoPublishAlias opening up the use of DeploymentPreferences
Steps to reproduce the issue:

Deploy a stack with the following template

# template.yml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Parameters:
  MyParam:
    Type: String
    Default: MyDefaultValue

Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./
      Handler: index.handler
      Runtime: nodejs12.x
      AutoPublishAlias: live
      Environment:
        Variables:
          MyEnv: !Ref MyParam
// index.js
export const handler = event => {
    console.log('MyEnv', process.env.MyEnv)
}

Deploy for a 2nd time with added parameter overrides --parameter-overrides MyParam=MyNewValue

Observed result:

$LATEST unqualified version has environment variable MyEnv=MyNewValue
live Alias'd version not updated and has environment variable MyEnv=MyDefaultValue

Expected result:

$LATEST unqualified version has environment variable MyEnv=MyNewValue
live Alias'd version updated and has environment variable MyEnv=MyNewValue

Duplicate issue #1777: Feature Request : When 'AWS::Serverless::LayerVersion' is updated then to publish a new version of the Lambda function
Created: 2020-11-07T11:35:01Z
Description:

Presently when the 'AutoPublishAlias' is set in the template for the Serverless Function, then during each update on the Function code publishes new Lambda Function Version. However, if we make only changes to the Lambda layer code and then deploy the changes through SAM-CLI. The new Lambda Function Version is not published and thus the Lambda function would still be using the older version of the Lambda Layer.
So it would be great if a new property similar to 'AutoPublishAlias' is created for the scenario where the Update only on the Lambda layer should publish a new version of the lambda Function.
Steps to reproduce the issue:

Create a SAM application with a Layer and then build & deploy it using SAM-CLI. (commands 'sam-build' & 'sam deploy')

SAM template ->
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  sam-app
  Sample SAM Template for sam-app

Globals:
  Function:
    Timeout: 3
    Layers:
      - Ref: MyLayer1

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function 
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.8
      AutoPublishAlias: live
      DeploymentPreference:
        Type: AllAtOnce
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: get

  MyLayer1:
    Type: AWS::Serverless::LayerVersion
    Properties:
      Description: testing layer
      ContentUri: ./layertest
      CompatibleRuntimes:
        - python3.8
      LayerName:
       Fn::Sub: ${AWS::StackName}-common
      RetentionPolicy: Delete


Next update the Lambda Layer code only and again run the commands 'sam-build' & 'sam deploy'.

Observed result:
The Lambda Layer is updated to a newer version and also the Lambda function with $LATEST version gets the Layer version updated. However the changes in Layer does not get reflected as the new version of Lambda function is not published.
Expected result:
The Lambda Layer is updated to a newer version and the new version of the Lambda Function is published .

Closing comment (2020-11-10T04:42:07Z): Hi @hnbalach Thanks for your feature request!
After trying with your template, I think the problem you observed is actually a bug that's reported in #1640.
Closing in favor of #1640