-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSM - parameter path and value changes are not updated in the stack. #7722
Comments
I'm seeing differing behaviour with the I've changed the value in SSM, but do not see any change when I deploy. |
The same happened to me. CDK diff is telling me that my layer gets replaced, but is telling me that none of my other stacks is being updated. Any idea of what's going on here ? |
This is because the values are being stored in your |
doesnt work for me |
After testing this the only scenario that I could reproduce was the first one - changing the parameterName. It looks like this is due to the way CloudFormation (and CDK) handles parameters, i.e. by default When you use When you use There are a couple of workarounds that you can use.
A permanent solution to this may be to update the |
OMG didnt know about this and saved my day... Thanks! |
Would be awesome if CDK could be updated with better default values here.. as currently this is an issue I have run into multiple times, and it's always one that I forget about until I have to deep dive into why things aren't working as expected. It's definitely not obvious/expected behaviour IMO. Edit: Also.. where are those values that using Edit 2: Haven't checked this out fully yet, but sounds promising:
Looking at Edit 3: Looking closer at the CDK docs for
Looking for more information about dynamic references:
|
Ha.. so apparently
Playing with this new const stripeSecretApiKey = StringParameter.fromStringParameterAttributes(
this,
'StripeSecretApiKey',
{
parameterName: `${parameterStoreNamespace}/stripe/secret_api_key`,
+ forceDynamicReference: true,
}
).stringValue Resulted in this Stack REDACTED
Parameters
- [-] Parameter StripeSecretApiKeyParameter: {"Type":"AWS::SSM::Parameter::Value<String>","Default":"/REDACTED/development/stripe/secret_api_key"}
Resources
[~] AWS::Lambda::Function FnStripeCustomerSubscriptionEventsHandler/Handler FnStripeCustomerSubscriptionEventsHandlerB91CA9D9
└─ [~] Environment
└─ [~] .Variables:
└─ [~] .stripeApiKey:
└─ @@ -1,3 +1,1 @@
- [-] {
- [-] "Ref": "StripeSecretApiKeyParameter"
- [-] }
+ [+] "{{resolve:ssm:/REDACTED/development/stripe/secret_api_key}}" For reference/comparison, changing the above const stripeSecretApiKey = StringParameter.valueForStringParameter(
this,
`${parameterStoreNamespace}/stripe/secret_api_key`
) Resulted in this Stack REDACTED
Parameters
- [-] Parameter StripeSecretApiKeyParameter: {"Type":"AWS::SSM::Parameter::Value<String>","Default":"/REDACTED/development/stripe/secret_api_key"}
+ [+] Parameter SsmParameterValue:--REDACTED--development--stripe--secret_api_key:REDACTED.Parameter SsmParameterValueREDACTEDdevelopmentstripesecretapikeyREDACTEDParameter: {"Type":"AWS::SSM::Parameter::Value<String>","Default":"/REDACTED/development/stripe/secret_api_key"}
Resources
[~] AWS::Lambda::Function FnStripeCustomerSubscriptionEventsHandler/Handler FnStripeCustomerSubscriptionEventsHandlerB91CA9D9
└─ [~] Environment
└─ [~] .Variables:
└─ [~] .stripeApiKey:
└─ [~] .Ref:
- ├─ [-] StripeSecretApiKeyParameter
+ └─ [+] SsmParameterValueREDACTEDdevelopmentstripesecretapikeyREDACTEDParameter Exploring the CDK code to see exactly how We can see the option being parsed from the CLI as We can see aws-cdk/packages/aws-cdk/lib/api/deploy-stack.ts Lines 136 to 143 in 6c75581
Which is used later on in that same file. When aws-cdk/packages/aws-cdk/lib/api/deploy-stack.ts Lines 265 to 272 in 6c75581
We can see the definitions of both of these functions here: aws-cdk/packages/aws-cdk/lib/api/util/cloudformation.ts Lines 399 to 419 in 6c75581
Which seems to describe how it tells CloudFormation to use the old values as:
We can see the definition of the aws-cdk/packages/aws-cdk/lib/api/util/cloudformation.ts Lines 422 to 504 in 6c75581
Of particular note/interest is the aws-cdk/packages/aws-cdk/lib/api/util/cloudformation.ts Lines 478 to 501 in 6c75581
Which suggests that:
The magic string is denoted by aws-cdk/packages/aws-cdk-lib/cx-api/lib/cxapi.ts Lines 41 to 47 in 6c75581
The
And is passed to aws-cdk/packages/aws-cdk/lib/api/deploy-stack.ts Lines 682 to 694 in 6c75581
Which will force a deploy when https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/lib/api/deploy-stack.ts#L735-L743 Which unfortunately seems to suggest that the behaviour for how this is actually resolved at deploy time looks like it is defined somewhere else.. either in CloudFormation itself, or perhaps somewhere in the CDK bootstrapper/related code/similar; not too sure. Looking deeper into how CDK template diffing works: The main aws-cdk/packages/@aws-cdk/cloudformation-diff/lib/diff-template.ts Lines 31 to 78 in 6c75581
Which then seems to call aws-cdk/packages/@aws-cdk/cloudformation-diff/lib/diff-template.ts Lines 96 to 115 in 6c75581
That seems to use one of various different
aws-cdk/packages/@aws-cdk/cloudformation-diff/lib/diff-template.ts Lines 10 to 29 in 6c75581
It seems to use aws-cdk/packages/@aws-cdk/cloudformation-diff/lib/diff/index.ts Lines 25 to 27 in 6c75581
And then calls aws-cdk/packages/@aws-cdk/cloudformation-diff/lib/diff/types.ts Lines 436 to 438 in 6c75581
And seems to just extend from aws-cdk/packages/@aws-cdk/cloudformation-diff/lib/diff/types.ts Lines 273 to 310 in 6c75581
Which then uses aws-cdk/packages/@aws-cdk/cloudformation-diff/lib/diff/util.ts Lines 1 to 60 in 6c75581
Going back to aws-cdk/packages/@aws-cdk/cloudformation-diff/lib/diff/types.ts Lines 9 to 21 in 6c75581
We can see that
|
Opened a tangentially related issue to allow |
I used following workaround: const fetchAlwaysNewVersionId = `ImportedVersion-${Date.now()}}`;
const codeObjectVersion = StringParameter.fromStringParameterAttributes(
this,
fetchAlwaysNewVersionId,
{
parameterName,
}
); Since each synth the id is changed (due to usage of Date.now())), it will be refetched. |
This is a terrible default behaviour! If I'm making a deployment I never want to risk deploying with stale parameter values! I nearly messed up my production environment with this unexpected stupidity. Is doing There is this one instead:
|
There are two ways of resolving ssm parameters (as long as it isn't a secure parameter):
ssm.StringParameter.valueForStringParameter
ssm.StringParameter.fromStringParameterAttributes
They behave differently, but according to the documentation I would expect them to behave the same.
Test by changing paths
ie: change the SSM path from one deployment to the next.
Retrieving by value does what I expect - it updates values when the path changes.
Retrieving by attributes does not. The value in the stack will not change.
Test by changing values
it doesn't matter what we change, the values in the stack do not change.
Reproduction Steps
https://github.com/brettswift/cdk-ssm-test
follow the README.md
shell scripts are there to demonstrate everything.
Environment
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: