aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM

Home Page:https://aws.amazon.com/serverless/sam/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Change Parameter's Default value doesn't reflect

siosphere opened this issue · comments

Description:

I am using AWS SAM to deploy my entire stack. Everything is codified within the yaml, and I use parameters for setting values of environment variables:

Parameters:
    MyParam:
        Type: String
        Default: foobar

It is being used within the yaml like:

Globals:
  Function:
    Environment:
        Variables:
          MY_PARAM: 
            Ref: MyParam

The Default value for this used to be bar but I updated it.

My deploy command does not use parameter-overrides for dev, only for production, so the default value is what should be used.

Upon deploying however, the old value (bar) is used. Even when I create new lambdas that have never been made before, the configuration will be the old value, which does not exist at all within my codebase anymore.

If I manually adjust the configuration of that env var in the aws console, it will revert to this old value the next time I deploy.

I would expect the updated Default value to be used if I am not overriding the value, otherwise whatever value I put in there first is used forever unless I override it, and that isn't very intuitive.

Steps to reproduce:

Configure an environment variable that references a param with a default value. Change the default value and make a new lambda, and it will get the old param value.

Observed result:

MY_PARAM | bar

Expected result:

MY_PARAM | foobar

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

{
  "version": "1.115.0",
  "system": {
    "python": "3.12.3",
    "os": "macOS-14.5-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "20.10.13",
    "aws_cdk": "Not available",
    "terraform": "1.2.9"
  },
  "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

Hi, thanks for bringing up the issue. For clarity's sake, are you using sam deploy to deploy your application, or is the only time you are using SAM is for creating the template? There is another repo for AWS SAM specifically, what kind of commands are you running to build/deploy?

I am using sam deploy to deploy the application
Technically it runs:

sam build
sam deploy --stack-name=...

Hey thanks for the response, after investigating it seems to be a bug on our side, we currently use previous values for parameters if they are present in the existing template already, regardless if the value is actually changed or not. Will mark it as a bug so the team can work on a fix. In the meantime as a workaround, when you deploy can you run the --parameter-overrides flag? Alternatively if you don't want to pass in that flag every time, deploying the stack once without the parameter should update the next deployment to have the new parameter value in it

Thanks, I did write a deployment script to pass in the --parameter-overrides which has been working, but occasionally I'll add a parameter, deploy, forget to add the override, change the default, and run into this again, so the fix will be appreciated eventually!

Thank you

We've had similar discussions in the past about this scenario. In short, this is behaviour we adopt from CloudFormation. The linked ticket has more detail. I'm going to close this issue in favour of the previous.

#4180

⚠️COMMENT VISIBILITY WARNING⚠️

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.
If you wish to keep having a conversation with other community members under this issue feel free to do so.