Fallback to default value instead of throwing error if SSM parameter not found #22281
Replies: 4 comments 4 replies
-
CFN Outputs can only come from the body of the cloudformation template. If you have some external resource that is brought in via cloudformation, you can use that, but if the resource doesn't exist then CloudFormation does not have a way to provide defaults. |
Beta Was this translation helpful? Give feedback.
-
@github-actions proposed-answer There is no fallback or default value mechanism that can be enabled - if the lookup fails to fetch the parameter for whatever reason, synthesis/deployment will fail. You could use a workaround by writing your own bash script which will make this call and writing a value to a file (supplying a default value if the call fails of course), and then reading this file when you run your CDK app. We recommend separating these processes - see the Commit cdk.context.json section for more information You could open a feature request to natively support this feature on the existing context providers, It does seem to contradict a safeguard we have in place to prevent unexpected changes from getting deployed, but if the use case is valid enough then we can consider allowing a default value when failing the lookup. |
Beta Was this translation helpful? Give feedback.
-
Closing the discussion for staleness. Please open a new discussion if you have further concerns. |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
My stack references a SSM parameter value, something like this:
When the stack is deployed it's throwing error
TestStack failed: Error [ValidationError]: Unable to fetch parameters [/test/param] from parameter store for this account.
Is there a way to suppress the error and fallback to a default value? I am not even sure if CloudFormation supports it.
PS: Ideally I should get the SSM parameter ready but in my scenario I can't when the stack is deployed first time. If it's impossible I am going to write a bash script which calls AWS CLI, fallback to default value on error and export as env var.
Beta Was this translation helpful? Give feedback.
All reactions