feat(core): Fn.findInMap supports default value#26543
feat(core): Fn.findInMap supports default value#26543mergify[bot] merged 18 commits intoaws:mainfrom
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.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
mrgrain
left a comment
There was a problem hiding this comment.
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?
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.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
scanlonp
left a comment
There was a problem hiding this comment.
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
| 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.
Is the last line necessary?
| * Prefer to use `CfnMapping.findInMap`. | ||
| * Warning: do not use with lazy maps. |
There was a problem hiding this comment.
Is this how we like to convey warnings / best practices?
There was a problem hiding this comment.
I think you should explain succinctly why you should not use with lazy maps
rix0rrr
left a comment
There was a problem hiding this comment.
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.
|
|
||
| /** | ||
| * @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.
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.
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
| * @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. | ||
| */ | ||
| public findInMap(key1: string, key2: string): string { | ||
| public findInMap(key1: string, key2: string, defaultValue?: string): string { |
There was a problem hiding this comment.
Ohmigod. Can this method be simplified if we reorganize it?
There was a problem hiding this comment.
Would be glad to, but not seeing a clear way. Think we ship it and someone enterprising can tidy it up later.
kaizencc
left a comment
There was a problem hiding this comment.
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.
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