aws cloudformation use previous value stack parameter
Asked by Adam Whiteland:

I have the need to update a cloudformation stack with some new parameters. I would like to do that using the aws cloudformation pipe like this:

```
script:
  - pipe: atlassian/aws-cloudformation-deploy:0.13.0
    variables:
      AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION: 'us-east-1'
      STACK_NAME: 'my-stack-name'
      TEMPLATE: 'https://s3.amazonaws.com/cfn-deploy-pipe/cfn-template.json'
      STACK_PARAMETERS: >
          [{
            "ParameterKey": "KeyName",
            "ParameterValue": "mykey"
          },
          {
            "ParameterKey": "DBUser",
            "ParameterValue": "mydbuser"
          },
          {
            "ParameterKey": "DBPassword",
            "ParameterValue": $DB_PASSWORD
```

But I also have parameters that I won't define in my pipeline and simply use what the previous value was for the parameter, which I would have setup manually through the aws console. This is how I would do it using the aws cli:

```
aws cloudformation update-stack --stack-name stack-name --use-previous-template --parameters ParameterKey=KeyName,ParameterValue=mykey ParameterKey=DBPassword,UsePreviousValue=true
```

Does the aws cloudformation pipe support the use of previous values in the STACK_PARAMETERS option?


Answers:
author: Igor Stoyanov
body: [@Adam Whiteland](/t5/user/viewprofilepage/user-id/647807) hi. Thanks for your question.  

You should use extra parameters:  

```
script:
  - pipe: atlassian/aws-cloudformation-deploy:0.13.0
    variables:
      AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION: 'us-east-1'
      STACK_NAME: 'my-stack-name'
      TEMPLATE: 'https://s3.amazonaws.com/cfn-deploy-pipe/cfn-template.json'
      STACK_PARAMETERS: >
          [{
            "ParameterKey": "KeyName",
            "ParameterValue": "mykey"
          },
          {
            "ParameterKey": "DBUser",
            "ParameterValue": "mydbuser"
          },
          {
            "ParameterKey": "DBPassword",
            "ParameterValue": $DB_PASSWORD
          }]
      EXTRA_PARAMETERS: >          {            "UsePreviousTemplate": true
          }
```

Regards, Igor

comments: author: Ashish Kataria
body: I don't think **UsePreviousTemplate** (for a stack) and **UsePreviousValue** (for a stack param) are the same.  

This is how they are different:

You don't need to specify the template if you use **UsePreviousTemplate**.

You don't need to specify the parameter value if you use **UsePreviousValue**.

I couldn't find any doc on the cloudformation pipe which clearly says that **UsePreviousValue** is supported.

Can you please specify some link to a doc to verify this?


author: Igor Stoyanov
body: [@Ashish Kataria](/t5/user/viewprofilepage/user-id/4577161) hi. Our pipe based on boto3 implementation.  
Here is link to [boto3 cloudformation update stack](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudformation.html#CloudFormation.Client.update_stack).  
In pipe it should work something like this:

```
      EXTRA_PARAMETERS: >        {            "UsePreviousTemplate": true,
            "Parameters":[                {                    'ParameterKey': 'string',                    'ParameterValue': 'string',                    'UsePreviousValue': True|False,                    'ResolvedValue': 'string'                }            ]
        }
```

Also [link to amazon guide](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-direct.html)  

Regards, Igor


Tags: aws

bitbucket-cloud

bitbucket-pipelines

cloud