-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
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 #31415
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
4dd29a3
to
65f14fe
Compare
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
65f14fe
to
8459bf7
Compare
2c515cf
to
f2e76f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
valueFromLookup
method: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
GetContextValueOptions
interface which is used to flag that we're not going to raise the error. Then, invalueFromLookup
, I set that flag totrue
if thedummyValue
is specified.valueFromLookup
then callsContextProvider.getValue
passing along those values.ContextProvider.getValue
is modified so that when it callsstack.reportMissingContextKey
it passes a modified set ofprops
which include thedefaultValue
and theignoreErrorOnMissingContext
flag.These finally land in the
aws-cdk
context 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 thedefaultValue
that 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
props
now contain some additional field.I added an integration test which calls
valueFromLookup
with adefaultValue
set and then confirms that no exception is raised and thatvalueFromLookup
returned thedefaultValue
NOTE
I considered that the changes made might need to be a part of the
cloud-assembly-schema
but 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
valueFromLookup
and the function doesn't appear to have a properTSDoc
header 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