-
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
feat(core): Fn.findInMap supports default value #26543
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.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
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.
This one should have an integration test!
Also if you read the announcement carefully, you'll notice it mentions the Language Extension Transform. What do you make of that in regards to this PR?
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.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
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.
I had a couple of lingering questions about comment guidelines and where code should live. I feel confident with the PR as is, but wanted to get feedback on those points in particular.
packages/aws-cdk-lib/core/README.md
Outdated
@@ -1058,6 +1058,28 @@ declare const regionTable: CfnMapping; | |||
regionTable.findInMap(Aws.REGION, 'regionName'); | |||
``` | |||
|
|||
An optional default value can also be passed to `findInMap`. If either key is not found in the map and the mapping is lazy, `findInMap` will return the default value. If the mapping is not lazy or either key is an unresolved token, the call to `findInMap` will return a token that resolves to `{ "Fn::FindInMap": [ "MapName", "TopLevelKey", "SecondLevelKey", { "DefaultValue": "DefaultValue" } ] }`. Note that the `AWS::LanguageExtentions` transform is added to enable the default value functionality. |
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.
Is the last line necessary?
* Prefer to use `CfnMapping.findInMap`. | ||
* Warning: do not use with lazy maps. |
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.
Is this how we like to convey warnings / best practices?
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.
I think you should explain succinctly why you should not use with lazy maps
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.
Nice! I've got some detail notes, but conditionally approved. Do with my comments as you will and feel free to remove the pr/do-not-merge
label yourself when you are feel you have addressed them to the degree that you want to 😉.
One final thing: in the title, you're describing the feature using the Python casing Fn.find_in_map
. In TypeScript the function is called Fn.findInMap
, and we usually use that casing to describe changes.
@@ -63,30 +63,41 @@ export class CfnMapping extends CfnRefElement { | |||
} | |||
|
|||
/** | |||
* @returns A reference to a value in the map based on the two keys. | |||
* @returns A reference to a value in the map based on the two keys. If mapping is lazy, the value from the map or default value is returned instead of the reference. |
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.
I'm pretty sure "lazy" means: only render the actual mapping to the template if there is at least one value that actually needs to be looked up from it at deploy time.
Conversely: if no value is ever read from the map, or all values can be resolved at synth time, then there is no need to render the map.
The line of documentation you added here doesn't help me understand that :).
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.
Felt that it wasn't accurate to say it returns a reference is sometimes it just passes a value. Also could help debug if the short circuit was not documented. Can add a line about the mapping behavior too
*/ | ||
public findInMap(key1: string, key2: string): string { | ||
public findInMap(key1: string, key2: string, defaultValue?: string): string { |
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.
Ohmigod. Can this method be simplified if we reorganize it?
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.
Would be glad to, but not seeing a clear way. Think we ship it and someone enterprising can tidy it up later.
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.
Have a few minor nits of my own lmao. Feel free to remove do-not-merge
when you address the one comment
* Prefer to use `CfnMapping.findInMap`. | ||
* Warning: do not use with lazy maps. |
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.
I think you should explain succinctly why you should not use with lazy maps
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). |
Cloudformation recently added support for a default value in the FindInMap intrinsic function. This adds that support.
Closes #26125.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license