aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

aws cloudformation deploy uses default values for parameters

Open jyrkiput opened this issue 9 years ago • 10 comments

https://github.com/aws/aws-cli/issues/2460 is about same issue, but I'm not sure if this was fixed. When using example from https://github.com/aws/aws-cli/issues/2466 value from stack is overridden with default when using aws cli version 1.11.83.

aws --version
aws-cli/1.11.83 Python/2.7.12+ Linux/4.10.0-21-generic botocore/1.5.46

I created following template

{
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description"              : "Test stack",
    "Parameters"               : {

        "TestParam2" : {
            "Description" : "Test param 2",
            "Type"        : "String",
            "Default": "exampledefault"
        }
    },
    "Resources" : {
        "examplebucket" : {
            "Type" : "AWS::S3::Bucket",
            "Properties": {
                "BucketName": { "Ref" : "TestParam2" }
            }
        }
    }
}

Then created a new stack with

aws cloudformation create-stack --stack-name aws-cli-test-s3 --template-body file://test.json

As expected, now I have S3 Bucket 'exampledefault'. Then I updated the stack with '--parameters ParameterKey=TestParam2,ParameterValue=exampleoverride',

aws cloudformation update-stack --stack-name aws-cli-test-s3 --template-body file://test.json --parameters ParameterKey=TestParam2,ParameterValue=exampleoverride

As expected, now I have S3 Bucket 'exampleoverride'. Then I updated stack again without explicitly defining 'TestParam2'

aws cloudformation update-stack --stack-name aws-cli-test-s3 --template-body file://test.json

Now 'exampleoverride' got deleted and 'exampledefault' was created.

I was expecting that the value set with '--parameters ParameterKey=TestParam2,ParameterValue=exampleoverride' on second update would be preserved.

Workaround for this is to use '--parameters ParameterKey=TestParam2, usePreviousValue=true'

jyrkiput avatar May 09 '17 04:05 jyrkiput

Thanks for reporting, we'll have this looked in to. Could you post a debug log for the final update stack? I'm wondering if usePreviousValue was set or not.

JordonPhillips avatar May 12 '17 17:05 JordonPhillips

Yeah, looks like use previous isn't being set. Here's the body being sent:

{
    'Action': 'UpdateStack',
    'StackName': 'aws-cli-test-s3',
    'Version': '2010-05-15',
    'TemplateBody': {
        "AWSTemplateFormatVersion": "2010-09-09",
        "Description": "Test stack",
        "Parameters": {
            "TestParam2": {
                "Description": "Test param 2",
                "Type": "String",
                "Default": "exampledefault"
            }
        },
        "Resources" : {
            "examplebucket": {
                "Type": "AWS::S3::Bucket",
                "Properties": {
                    "BucketName": {
                        "Ref": "TestParam2"
                    }
                }
            }
        }
    }
}

JordonPhillips avatar May 12 '17 19:05 JordonPhillips

You are using create-stack and update-stack commands. They are plain wrappers to CloudFormation APIs. With these APIs, its your responsibility to ask CFN to use previous value when necessary, otherwise it will fall back to the default. (granted this is slightly confusing, but that's how the API works)

The extra functionality of automatically specifying UsePreviousValue comes from aws cloudformation deploy command. The bug you are referring to fixes deploy command.

prokilogrammer avatar May 31 '17 22:05 prokilogrammer

Would it be possible to implement this is a --use-previous-values flag for update-stack? This would be useful where the only change has been to the resolved values of parameters which are of type AWS::SSM::Parameter::Value Currently to achieve this every parameter must be listed out as ParameterKey=ParameterName,UsePreviousValue=true

skuzzer avatar Mar 16 '18 03:03 skuzzer

Any updates on @skuzzer 's suggestion for a stack-wide --use-previous-parameters flag?

Currently I run into a similar issue, where I want to update my Cloudformation stack to update one particular Parameter. Listing all other parameters in this case will be quite hard.

zodiac403 avatar Aug 05 '18 08:08 zodiac403

Just hitting exactly the same issue. SSM Parameter stores are getting template defaults instead of what is already present on the stack.

boianmihailov avatar Jan 29 '19 11:01 boianmihailov

18 months later any update on a --use-previous-values flag?

Ltadrian avatar Sep 23 '19 15:09 Ltadrian

I have created a python script that could be helpful update_cf_stack_params.py

taherbs avatar Feb 20 '20 15:02 taherbs

Greetings! It looks like this issue hasn’t been active in longer than one year. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.

github-actions[bot] avatar Nov 12 '21 23:11 github-actions[bot]