fix(ssm): update ssm-context to prevent raising an error on missing parameter#31415
fix(ssm): update ssm-context to prevent raising an error on missing parameter#31415mergify[bot] merged 5 commits intoaws:mainfrom dsilbergleithcu-godaddy:prevent-ssm-context-provider-errors
Conversation
aws-cdk-automation
left a comment
There was a problem hiding this comment.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.
Updates StringParameter.valueFromLookup with an optional "defaultValue" When specified this value will be used: - in place of the standard dummyValue - to signal that an Error should not be raised during synthesis if the parameter is not found in the account. Test are updated to prove that this works
rix0rrr
left a comment
There was a problem hiding this comment.
Looks good! One small thing...
Co-authored-by: Rico Hermans <rix0rrr@gmail.com>
|
➡️ PR build request submitted to A maintainer must now check the pipeline and add the |
|
sending thru our test pipeline will add the necessary labels + approve when its done |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
|
Comments on closed issues and PRs are hard for our team to see. |
Updates StringParameter.valueFromLookup with an optional "defaultValue" When specified this value will be used:
Test are updated to prove that this works
Issue # (if applicable)
Resolves #7051
There are some closed issues which also benefit from this change:
Reason for this change
We have a library which has a fixed set of SSM parameters on which it depends. The values from those parameters are made available as attributes of a custom Stack. We have many users in many different AWS accounts, and not all of the parameters are guaranteed to exist. This is okay. In general, teams would simply not use those values and be happy with that outcome. Unfortunately, CDK crashes when you look up an SSM parameter that does not exist in the account. This is unacceptable.
Description of changes
To address the issue described above, I implemented an optional parameter on the
valueFromLookupmethod:defaultValue. The idea is that if this value is specified, and we fail to look up a parameter in the account, we will return this value and suppress the Error that is currently raised when a parameter is not found.To implement that functionality, I added a field to the
GetContextValueOptionsinterface which is used to flag that we're not going to raise the error. Then, invalueFromLookup, I set that flag totrueif thedummyValueis specified.valueFromLookupthen callsContextProvider.getValuepassing along those values.ContextProvider.getValueis modified so that when it callsstack.reportMissingContextKeyit passes a modified set ofpropswhich include thedefaultValueand theignoreErrorOnMissingContextflag.These finally land in the
aws-cdkcontext provider forssm-parameter. That code has been updated so that if the value is not found in SSM, and we're told to suppress the error, then we'll simply return thedefaultValuethat was passed in.Description of how you validated changes
I added a unit tests which covers when the default value is set. I also updated the original unit test as the
propsnow contain some additional field.I added an integration test which calls
valueFromLookupwith adefaultValueset and then confirms that no exception is raised and thatvalueFromLookupreturned thedefaultValueNOTE
I considered that the changes made might need to be a part of the
cloud-assembly-schemabut chose to work around that for now. I'm open to incorporating them there if that's a more correct path.NOTE 2
I'm unsure about how to update API documentation for this change. This does alter the public API for
valueFromLookupand the function doesn't appear to have a properTSDocheader on it. Please let me know if there's a proper way for me to update the documentation.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license