in samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py [0:0]
def handle_find_in_map(self, intrinsic_value, ignore_errors):
"""
{ "Fn::FindInMap" : [ "MapName", "TopLevelKey", "SecondLevelKey"] } This function will then lookup the
specified dictionary in the Mappings dictionary as mappings[map_name][top_level_key][second_level_key].
This intrinsic function will resolve all the objects within the function's value and check their type.
The format of the Mappings dictionary is:
"Mappings": {
"map_name": {
"top_level_key": {
"second_level_key": "value"
}
}
}
}
Parameter
----------
intrinsic_value: list, dict
This is the value of the object inside the Fn::FindInMap intrinsic function property
Return
-------
A string with the resolved attributes
"""
arguments = self.intrinsic_property_resolver(
intrinsic_value, ignore_errors, parent_function=IntrinsicResolver.FN_FIND_IN_MAP
)
verify_intrinsic_type_list(arguments, IntrinsicResolver.FN_FIND_IN_MAP)
verify_number_arguments(arguments, num=3, property_type=IntrinsicResolver.FN_FIND_IN_MAP)
map_name = self.intrinsic_property_resolver(
arguments[0], ignore_errors, parent_function=IntrinsicResolver.FN_FIND_IN_MAP
)
top_level_key = self.intrinsic_property_resolver(
arguments[1], ignore_errors, parent_function=IntrinsicResolver.FN_FIND_IN_MAP
)
second_level_key = self.intrinsic_property_resolver(
arguments[2], ignore_errors, parent_function=IntrinsicResolver.FN_FIND_IN_MAP
)
verify_intrinsic_type_str(map_name, IntrinsicResolver.FN_FIND_IN_MAP, position_in_list="first")
verify_intrinsic_type_str(top_level_key, IntrinsicResolver.FN_FIND_IN_MAP, position_in_list="second")
verify_intrinsic_type_str(second_level_key, IntrinsicResolver.FN_FIND_IN_MAP, position_in_list="third")
map_value = self._mapping.get(map_name)
verify_intrinsic_type_dict(
map_value,
IntrinsicResolver.FN_FIND_IN_MAP,
position_in_list="first",
message="The MapName is missing in the Mappings dictionary in Fn::FindInMap for {}".format(map_name),
)
top_level_value = map_value.get(top_level_key)
verify_intrinsic_type_dict(
top_level_value,
IntrinsicResolver.FN_FIND_IN_MAP,
message="The TopLevelKey is missing in the Mappings dictionary in Fn::FindInMap "
"for {}".format(top_level_key),
)
second_level_value = top_level_value.get(second_level_key)
verify_non_null(
second_level_value,
IntrinsicResolver.FN_FIND_IN_MAP,
message="The SecondLevelKey is missing in the Mappings dictionary in Fn::FindInMap "
"for {}".format(second_level_key),
)
return second_level_value