What would be a good strategy to have a default value on mappings?
I.E.
I have a parameter called country
Based on that country
I reference a DNS using mappings
"Mappings" : {
"DNS":{
"us" : {"dns" : "mypage.us.com", "ttl" : "600"},
"mx" : {"dns" : "mypage.default.com", "ttl" : "300"},
"ar" : {"dns" : "mypage.default.com", "ttl" : "300"},
"br" : {"dns" : "mypage.default.com", "ttl" : "300"}
}
}
If us
it's been mapped:
{ "Fn::FindInMap" : [ "DNS", { "Ref" : "country" }, "dns" ]}
I get "mypage.us.com"
for the other countries I've created a huge list of countries with a default value mypage.default.com
, in the future, this values will be changing and we will be adding more countries, is there a better approach to this?
A Mappings section is a top level section of a CloudFormation template. It is used to define maps, their keys and values which can be then referenced in your template. Here is a simplified example of a Mappings section. It contains one Map, AnExampleMapping .
There is no limit to the number of CloudFormation Templates per Region.
Verify quotas for all resource types Each service can have various limits that you should be aware of before launching a stack. For example, by default, you can only launch 2000 CloudFormation stacks per region in your Amazon Web Services account.
An array of integers or floats that are separated by commas. AWS CloudFormation validates the parameter value as numbers; however, when you use the parameter elsewhere in your template (for example, by using the Ref intrinsic function), the parameter value becomes a list of strings.
The only way I was able to do this was to chain Fn::If
statements instead of using the map. I tried using a combination of Fn::If
and Fn::FindInMap
but Fn::FindInMap
will always raise an error it if can't find the mapping.
Therefore the only solution for me was to resort to using something like the following (for me it was setting ecs memory based on instance type):
Conditions:
IsT2Micro: !Equals [!Ref InstanceType, "t2.micro"]
IsT2Small: !Equals [!Ref InstanceType, "t2.small"]
...
taskdefinition:
Type: AWS::ECS::TaskDefinition
Properties:
...
Memory: !If [ IsT2Micro, 900, !If [ IsT2Small, 1900, !Ref "AWS::NoValue"]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With