Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value on mappings AWS CloudFormation

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?

like image 472
Marco Herrarte Avatar asked Mar 09 '16 22:03

Marco Herrarte


People also ask

What are Mappings in AWS CloudFormation?

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 .

What is the default limit for CloudFormation templates per region?

There is no limit to the number of CloudFormation Templates per Region.

What is the default limit for CloudFormation templates per region choose the correct answer from the options below?

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.

What are AWS CloudFormation parameters?

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.


1 Answers

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"]]
like image 145
Steve Smith Avatar answered Sep 27 '22 19:09

Steve Smith