Fn::FindInMap enhancements
When you add the AWS::LanguageExtensions
transform in a AWS CloudFormation template,
you can use intrinsic functions to define the fields of Fn::FindInMap
. You can
also use a new optional field to return a default value if a mapping is not found.
For more information about the AWS::LanguageExtensions
transform, see AWS::LanguageExtensions transform.
For more information about the Fn::FindInMap
intrinsic function, see Fn::FindInMap.
Declaration
JSON
{ "Fn::FindInMap" : [ "
MapName
", "TopLevelKey
", "SecondLevelKey
", {"DefaultValue": "DefaultValue
"} ] }
YAML
Syntax for the full function name:
Fn::FindInMap:
- MapName
- TopLevelKey
- SecondLevelKey
- DefaultValue:DefaultValue
Syntax for the short form:
!FindInMap
- MapName
- TopLevelKey
- SecondLevelKey
- DefaultValue:DefaultValue
Parameters
- DefaultValue
-
The value that
Fn::FindInMap
will resolve to if theTopLevelKey
and/orSecondLevelKey
can not be found from theMapName
map. This field is optional.
All parameters MapName
, TopLevelKey
,
SecondLevelKey
, and DefaultValue
can be an intrinsic
function as long as it's able to resolve to a valid value during the transform.
Example
The following is an example of using intrinsic functions to define the top level key:
JSON
{ //... "Transform": "AWS::LanguageExtensions", //... "Fn::FindInMap": [ "MyMap", { "Fn::Select": [ 0, { "Fn::Split": [ "|", { "Ref": "InputKeys" } ] } ] }, "SecondKey" ] //... }
YAML
Transform: 'AWS::LanguageExtensions' #... !FindInMap: [MyMap, !Select [0, !Split [|, !Ref InputKeys]], SecondKey] #...
The following is an example of using default values:
JSON
{ //... "Transform": "AWS::LanguageExtensions", //... "Fn::FindInMap": [ "InstanceConfiguration", { "Ref": "AWS::Region" }, "Type", { "DefaultValue": "m5.small" } ] //... }
YAML
Transform: 'AWS::LanguageExtensions' #... !FindInMap - 'InstanceConfiguration' - !Ref 'AWS::Region' - 'Type' - DefaultValue: m5.small #...
Supported functions
You can use the following functions in the parameters of Fn::FindInMap:
enhancements:
-
Fn::Split
- Unless it’s used for the default value,Fn::Split
has to be used in conjunction with intrinsic functions that produce a string, such asFn::Join
orFn::Select
.