Aws-cli: aws cloudformation deploy uses default values for parameters

Created on 9 May 2017  路  9Comments  路  Source: aws/aws-cli

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'

cloudformation packagdeploy customization feature-request

Most helpful comment

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

All 9 comments

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.

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"
                    }
                }
            }
        }
    }
}

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.

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

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.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings