Open nikovirtala opened 2 years ago
I guess this is more a @aws-cdk/core
than @aws-cdk/aws-ssm
issue because it is related to the CloudFormation ChangeSet creation.
const x = aws_ssm.StringParameter.fromStringParameterAttributes(this, 'X', {
parameterName: parameterName,
}).stringValue;
Here the second parameter id
is 'X', when you run
aws ssm delete-parameter --name "X"
you are deleting the parameter with id 'X', not parameter with name 'X'. Try changing parameterId to get your desired result:
const parameterName = 'Y';
const parameterId = 'Y';
const x = aws_ssm.StringParameter.fromStringParameterAttributes(this, parameterId, {
parameterName: parameterName,
}).stringValue;
instead.
@tezz-io I don't want to (in some cases even cannot) change the parameter construct Id, which causes a re-creation, I want to update the currently existing parameter value.
I want to update the currently existing parameter value.
You mean the imported parameter name, not the value, right?
You mean the imported parameter name, not the value, right?
The Cloudformation parameter value (which is the SSM Parameter name).
We have the --no-previous-parameters
option when deploying which will unblock here. Does this work for you?
@peterwoodworth why do you think this is not a bug?
I don't think anything is happening here that's unexpected - See CloudFormation docs on SSM Parameter types and CDK docs on parameters
CDK will use previous parameter values by default - and CloudFormation will use the previous SSM parameter key if no value is specified. Here, no parameter value is being supplied to the parameter that is only having its default value be changed, so it will remain the same between deployments.
We need to clarify this functionality in the SSM docs
CDK will use previous parameter values by default - and CloudFormation will use the previous SSM parameter key if no value is specified. Here, no parameter value is being supplied to the parameter that is only having its default value be changed, so it will remain the same between deployments.
But that's an implementation detail. When you consider the code in the issue:
const x = aws_ssm.StringParameter.fromStringParameterAttributes(this, 'X', {
parameterName: parameterName,
}).stringValue;
The fact that the parameterName
is implemented as a Parameter Type with a default value is an implementation detail. It makes sense that when a user changes the value of parameterName
, they expect the construct to refer to a different parameter. The fact that it doesn't is a bug, in my opinion. The fact that it's the expected behavior due to the current implementation is just the cause of the bug, isn't it?
It makes sense that when a user changes the value of parameterName, they expect the construct to refer to a different parameter
I agree with you that this is a reasonable expectation to have, and ideally it should work this way. We want to abstract ourselves from CloudFormation right? Thanks for pushing back here
I've been struggling to think of how we could work around this due to being bound by CloudFormation, but I think there's a couple potential options that would need a bit more research, and I'm not completely sure if either option is viable:
Since there's a pretty simple workaround here and the reason for this isn't obvious without some research, we should absolutely call this out in the docs anyway.
Describe the bug
When CDK creates CloudFormation Stack Parameter from SSM Parameter, and the SSM Parameter name is changed, there is no or no easy way to get the change deployed.
Expected Behavior
CloudFormation Stack Parameter value will be read from the renamed SSM Parameter.
Current Behavior
CloudFormation Stack Parameter value stuck to the initially deployed SSM Parameter.
Reproduction Steps
aws ssm put-parameter --name "X" --type String --value "something something"
aws ssm put-parameter --name "Y" --type String --value "something new"
parameterName
value toY
cdk diff
, it should show following:[ ] Delete the SSM Parameter "X" with e.g. AWS CLI: aws ssm delete-parameter --name "X"
[ ] Deploy the updated stack – it fails!
Possible Solution
Allow user to set "UsePreviousValue":
false
for Parameters when creating CloudFormation ChangeSet – that's how you solve this type of problem in CloudFormation.Additional Information/Context
CDK verbose output when trying to create ChangeSet:
UpdateParameters.template.json
after togglingparameterName
toY
(Conditions redacted):CDK CLI Version
2.24.1 (build 585f9ca)
Framework Version
No response
Node.js Version
v16.15.0
OS
macOS Monterey Version 12.4
Language
Typescript
Language Version
4.6.4
Other information
No response