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

cloudformation deploy fails if new parameters are not overridden even if they have default value

Open kskory opened this issue 9 years ago • 22 comments

After adding new parameters to the template, it has to be deployed with --parameters-override for all the new parameters even if they have default value, otherwise deploy fails with:

An error occurred (ValidationError) when calling the CreateChangeSet operation: Invalid input for parameter key Param2. Cannot specify usePreviousValue as true for a parameter key not in the previous template

To reproduce, deploy simple template:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A hello world application.
Parameters:
  Param1:
    Default: 123
    Type: String
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs4.3
      CodeUri: ./hello.zip

add some parameter to it:

...
Parameters:
  Param1:
    Default: 123
    Type: String
  Param2:
    Default: 123
    Type: String
...

Try to deploy again, it fails with aforementioned error.

kskory avatar May 12 '17 11:05 kskory

Thanks for the report, this seems to be related to a previous bugfix: #2573

JordonPhillips avatar May 12 '17 17:05 JordonPhillips

Its not a regression to previous bugfix, but a new corner case that the code doesn't handle well.

Unfortunately, this is a tough one because I need to pull down the latest template from stack, parse parameters, diff with the new template and merge current-template, new-template and overrides to come up with list of accurate UsePreviousValues. For the majority use-case, this extra call is unnecessary.

Potential fix would be to use get-template-summary call instead of describe-stacks to check presence of stack AND fetch parameter information.

Until we fix this bug, you can override the parameter explicitly when you add a new parameter with default value. Just once when you first update the stack. Afterwards, UsePreviousValue should work as expected

prokilogrammer avatar May 31 '17 23:05 prokilogrammer

This is still an issue as of awscli version 1.11.146.

ffxsam avatar Sep 05 '17 19:09 ffxsam

Just say you are adding ServiceCount, do it this way:

aws cloudformation deploy --template-file ./build/cfn-package.yml --stack-name dev-v2 --region us-west-2 --capabilities CAPABILITY_NAMED_IAM CAPABILITY_IAM --parameter-overrides ServiceCount=1

billnbell avatar Oct 07 '17 17:10 billnbell

In the modern world of infrastructure creates/updates happening via CI or some other automation one-time hacks to put the new parameter there really don't cut it.

btisdall avatar Oct 10 '17 06:10 btisdall

Just adding another voice here.

This isn't a "corner case." The way this currently works doesn't play nice with CI at all, and it's something I have to hack around with manual workarounds on a regular basis. Using the default if no previous value exists should be the expected behavior.

mga226 avatar Oct 17 '17 16:10 mga226

Shameless plug for #2943 which provides a alternate mode of operation (never re-use stack params because that's a deployment anti-pattern IMO) and thereby avoids this problem. I realise this won't be satisfactory for everyone but I thought I'd mention it.

btisdall avatar Nov 08 '17 05:11 btisdall

btisdall: this is not the same thing. I agree that we should not re-use stack params, but the default should work, and we should not have to override them.

billnbell avatar Nov 08 '17 18:11 billnbell

I actually disagree. I think reusing params is extremely handy. No way would I want to have to specify every single parameter every time I wanted to re-deploy. Sure, in a CI/CD environment that would probably make sense. But often times I'm running build & deploy from the command line.

ffxsam avatar Nov 08 '17 18:11 ffxsam

In particular when doing stack updates, where you might not be aware of all the parameters that were set at creation time. We currently have scripts for updates which pull all of the original parameters from the stack and then override the ones we're changing to prevent things like regression to defaults, but it would be nice to not have to do that.

Also because of the behavior cited here adding a parameter to a stack means breaking any code/procedure/deployment that does not know about the new parameter. That would make sense if the parameter did not have a default, but that's what defaults are supposed to do: make a selection when none is provided by the user.

dgcgh avatar Nov 08 '17 18:11 dgcgh

@billnbell and others: I'm fully aware it's not the same thing, I thought my comment made this clear. I absolutely agree that new template params with a default should just work with the command as it is. And I don't deny parameter re-use is handy, I just happen to think it's a bad choice for some situations because you're effectively pushing your infrastructure configuration out of code into a remote system.

btisdall avatar Nov 08 '17 19:11 btisdall

👍 Any news on this?

larryboymi avatar Jan 09 '18 20:01 larryboymi

Ran into this same issue today.

ldm314 avatar Jan 09 '18 22:01 ldm314

same issue here, any updates?

libert-xyz avatar Jan 11 '18 19:01 libert-xyz

Same problem here :/

foxx avatar Jan 20 '18 15:01 foxx

This is still an issue with Cloud9 Lambda functions. It's not possible to add a parameter to the SAM template file. And the click-to-deploy functionality does not offer a way to fix it via the command line.

ericzbeard avatar Mar 20 '18 17:03 ericzbeard

bug has still not been fixed on aws cli

aws-adjustmentbureau avatar Aug 28 '19 19:08 aws-adjustmentbureau

Have same issue with aws cli and Lambda.

oxsannikova avatar Apr 08 '20 14:04 oxsannikova

same issues

smyja avatar Apr 13 '20 18:04 smyja

An error occurred (ValidationError) when calling the CreateStack operation: Parameters: [PrivateSubnet1CIDR, PublicSubnet2CIDR, PrivateSubnet2CIDR, PublicSubnet1CIDR] do not exist in the template My solution-I have not proper indentation after proper indentation it works

mynamerahulkumar avatar Nov 17 '20 00:11 mynamerahulkumar