{"id":1113,"date":"2018-02-20T01:28:10","date_gmt":"2018-02-20T01:28:10","guid":{"rendered":"http:\/\/wiki.thomasandsofia.com\/?p=1113"},"modified":"2018-02-20T02:25:52","modified_gmt":"2018-02-20T02:25:52","slug":"cloudformation-mappings","status":"publish","type":"post","link":"https:\/\/wiki.thomasandsofia.com\/?p=1113","title":{"rendered":"CloudFormation Mappings"},"content":{"rendered":"<p><a href=\"https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8161736?start=0\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8161736?start=0<\/a><\/p>\n<p><a href=\"http:\/\/wiki.thomasandsofia.com\/2018\/02\/18\/cloud-formation-main-menu\/\" target=\"_blank\" rel=\"noopener\">Course Main Menu<\/a><\/p>\n<h2>Section 5 Main Menu<\/h2>\n<ul>\n<li><a href=\"#mappings\">Mappings Overview<\/a><\/li>\n<li><a href=\"#find\">Fn::FindInMap<\/a><\/li>\n<li><a href=\"#hands\">Mappings Hands On<\/a><\/li>\n<li><a href=\"#pseudo\">Pseudo Parameters in CloudFormation<\/a><\/li>\n<li><a href=\"#quiz\">Quiz<\/a><\/li>\n<\/ul>\n<p><a name=\"mappings\"><\/a><\/p>\n<h2>Mappings Overview<\/h2>\n<p>What are Mappings?<\/p>\n<ul>\n<li>Mappings are fixed variables within your CF Template<\/li>\n<li>They&#8217;re very handy to differentiate between different environments (dev vs. prod), Regions, AMI types, etc.<\/li>\n<li>All the values are hardcoded within the template<\/li>\n<li>Example:\n<ul>\n<li>Mappings:\n<ul>\n<li>Mapping01:\n<ul>\n<li>Key01:\n<ul>\n<li>Name: Value01<\/li>\n<\/ul>\n<\/li>\n<li>Key02\n<ul>\n<li>Name: Value02<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>RegionMap:\n<ul>\n<li>us-east-1:\n<ul>\n<li>&#8220;32&#8221;: &#8220;ami-6411e20d&#8221;<\/li>\n<li>&#8220;64&#8221;: &#8220;ami-7a11e213&#8221;<\/li>\n<\/ul>\n<\/li>\n<li>us-west-1:\n<ul>\n<li>&#8220;32&#8221;: &#8220;ami-c9c7978c&#8221;<\/li>\n<li>&#8220;64&#8221;: &#8220;ami-cfc7978a&#8221;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>When to use Mappings vs. Parameters?<\/p>\n<ul>\n<li>Mappings are great when you know in advance all the values that can be taken and that they can be deduced from variables such as:\n<ul>\n<li>Region<\/li>\n<li>Availability Zone<\/li>\n<li>AWS Account #<\/li>\n<li>Environment (dev vs. prod)<\/li>\n<li>Etc<\/li>\n<\/ul>\n<\/li>\n<li>They allow safer control over the template (avoid user errors?)<\/li>\n<li>Use Parameters when the values are really user specific<\/li>\n<\/ul>\n<p><a name=\"find\"><\/a><\/p>\n<h2>Fn::FindInMap (Accessing Mapping Values)<\/h2>\n<p><a href=\"https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8161738?start=0\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8161738?start=0<\/a><\/p>\n<ul>\n<li>JSON: &#8220;Fn::FindInMap [MapName, TopLevelKey, SecondLevelKey]<\/li>\n<li>YAML: &#8220;!FindInMap [MapName, TopLevelKey, SecondLevelKey]\n<ul>\n<li>ImageId: !FindInMap [RegionMap, !Ref &#8220;AWS::Region&#8221;, 32]<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><a name=\"hands\"><\/a><\/p>\n<h2>Mappings Hands On<\/h2>\n<pre>Parameters:\r\n  EnvironmentName:\r\n    Description: Environment Name\r\n    Type: String\r\n    AllowedValues: [development, production]\r\n    ConstraintDescription: must be development or production\r\n\r\nMappings:\r\n  AWSRegionArch2AMI:\r\n    us-east-1:\r\n      HVM64: ami-6869aa05\r\n    us-west-2:\r\n      HVM64: ami-7172b611\r\n    us-west-1:\r\n      HVM64: ami-31490d51\r\n    eu-west-1:\r\n      HVM64: ami-f9dd458a\r\n    eu-central-1:\r\n      HVM64: ami-ea26ce85\r\n    ap-northeast-1:\r\n      HVM64: ami-374db956\r\n    ap-northeast-2:\r\n      HVM64: ami-2b408b45\r\n    ap-southeast-1:\r\n      HVM64: ami-a59b49c6\r\n    ap-southeast-2:\r\n      HVM64: ami-dc361ebf\r\n    ap-south-1:\r\n      HVM64: ami-ffbdd790\r\n    us-east-2:\r\n      HVM64: ami-f6035893\r\n    sa-east-1:\r\n      HVM64: ami-6dd04501\r\n    cn-north-1:\r\n      HVM64: ami-8e6aa0e3\r\n  EnvironmentToInstanceType:\r\n    development:\r\n      instanceType: t2.micro\r\n    # we want a bigger instance type in production\r\n    production:\r\n      instanceType: t2.small\r\n\r\nResources:\r\n  EC2Instance:\r\n    Type: AWS::EC2::Instance\r\n    Properties:\r\n      InstanceType: !FindInMap [EnvironmentToInstanceType, !Ref 'EnvironmentName', instanceType]\r\n      # Note we use the pseudo parameter AWS::Region\r\n      ImageId: !FindInMap [AWSRegionArch2AMI, !Ref 'AWS::Region', HVM64]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><a name=\"pseudo\"><\/a><\/p>\n<h2>Pseudo Parameters in CloudFormation<\/h2>\n<ul>\n<li>AWS allows pseudo parameters in any CF template<\/li>\n<li>These can be use at any time and are enabled by default<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<th>Reference Value<\/th>\n<th>Example Return Value<\/th>\n<\/tr>\n<tr>\n<td>AWS::AccountId<\/td>\n<td>1234567890<\/td>\n<\/tr>\n<tr>\n<td>AWS::NotificationARNs<\/td>\n<td>[arn:aws:sns:us-east-1:123456789012:MyTopic]<\/td>\n<\/tr>\n<tr>\n<td>AWS::NoValue<\/td>\n<td>Does not return a value<\/td>\n<\/tr>\n<tr>\n<td>AWS::Region<\/td>\n<td>us-east-2<\/td>\n<\/tr>\n<tr>\n<td>AWS::StackId<\/td>\n<td>arn:aws:sns:us-east-1:123456789012:stack\/MyStack\/1C2Fa620-982a-aae3-aff7-50e2416294e0<\/td>\n<\/tr>\n<tr>\n<td>AWS::StackName<\/td>\n<td>MyStack<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a name=\"quiz\"><\/a><\/p>\n<h2>Quiz<\/h2>\n<h4>When is a mapping a good choice against a parameter?<\/h4>\n<ul>\n<li><strong>When you know all the possible values of a variable in advance<\/strong><\/li>\n<li>To give flexibility to the user<\/li>\n<\/ul>\n<p>Mappings have to be completely exhaustive and thus they reduce the template flexibility.\u00a0 Parameters are perfect for highly changing values, while mappings are great for stable values that won&#8217;t change in time, but can be determined ahead of time.<\/p>\n<h4>What are Pseudo Parameters<\/h4>\n<ul>\n<li><strong>They&#8217;re pre-populated AWS parameters that you can reference in your template, to figure out the region, stack name, etc.<\/strong><\/li>\n<li>They&#8217;re user defined parameters that can only be named the way AWS wants it.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8161736?start=0 Course Main Menu Section 5 Main Menu Mappings Overview Fn::FindInMap Mappings Hands On Pseudo Parameters in CloudFormation Quiz Mappings Overview What are Mappings? Mappings are fixed variables within your CF Template They&#8217;re very handy to differentiate between different environments (dev vs. prod), Regions, AMI types, etc. All the values are hardcoded within the template ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/wiki.thomasandsofia.com\/?p=1113\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-1113","post","type-post","status-publish","format-standard","hentry","category-cloudformation"],"_links":{"self":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/1113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1113"}],"version-history":[{"count":8,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/1113\/revisions"}],"predecessor-version":[{"id":1122,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/1113\/revisions\/1122"}],"wp:attachment":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}