{"id":1092,"date":"2018-02-18T22:40:55","date_gmt":"2018-02-18T22:40:55","guid":{"rendered":"http:\/\/wiki.thomasandsofia.com\/?p=1092"},"modified":"2018-02-19T00:09:25","modified_gmt":"2018-02-19T00:09:25","slug":"cloudformation-parameters","status":"publish","type":"post","link":"https:\/\/wiki.thomasandsofia.com\/?p=1092","title":{"rendered":"CloudFormation Parameters"},"content":{"rendered":"<p><a href=\"https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8151200?start=0\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8151200?start=0<\/a><\/p>\n<p><a href=\"http:\/\/wiki.thomasandsofia.com\/2018\/02\/18\/cloud-formation-main-menu\/\">Course Main Menu<\/a><\/p>\n<h2>Section Menu<\/h2>\n<ul>\n<li><a href=\"#overview\">Parameters Overview<\/a><\/li>\n<li><a href=\"#theory\">Theory &amp; Hands On<\/a><\/li>\n<li><a href=\"#how\">How to Reference a Parameter<\/a><\/li>\n<li><a href=\"#quiz\">Quiz<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Parameters Overview<\/h2>\n<h3>What are Parameters?<\/h3>\n<ul>\n<li>Parameters are a way to provide inputs to your AWS CF template<\/li>\n<li>They are important to know about if:\n<ul>\n<li>You want to reuse your templates across the company<\/li>\n<li>Some inputs cannot be determined ahead of time\n<ul>\n<li>Instance Size<\/li>\n<li>Instance Name<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Parameters are extremely powerful, controlled and can prevent errors from happening in your templates thanks to types.<\/li>\n<\/ul>\n<p>When should you use a parameter?<\/p>\n<ul>\n<li>Ask yourself this:\n<ul>\n<li>Is my CF resource configuration likely to change in the future?\n<ul>\n<li>YES!<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>You won&#8217;t have to re-upload a template to change its content\n<ul>\n<li>You only change the parameters<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><a name=\"theory\"><\/a><\/p>\n<h2>Theory &amp; Hands On<\/h2>\n<p><a href=\"https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8161716?start=0\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8161716?start=0<\/a><\/p>\n<p><a href=\"https:\/\/docs.aws.amazon.com\/AWSCloudFormation\/latest\/UserGuide\/parameters-section-structure.html\" target=\"_blank\" rel=\"noopener\">AWS Documentation Link<\/a><\/p>\n<p><strong>Parameters can be controlled by the following settings<\/strong><\/p>\n<ul>\n<li>Type\n<ul>\n<li>String<\/li>\n<li>Number<\/li>\n<li>CommaDelimitedList<\/li>\n<li>List&lt;Type&gt;\n<ul>\n<li>Allows you to select multiple answers.<\/li>\n<\/ul>\n<\/li>\n<li>AWS Parameter\n<ul>\n<li>To help catch invalid values<\/li>\n<li>Match these against existing values in the AWS Account<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Description<\/li>\n<li>Constraints\n<ul>\n<li>ContraintDescription (String)<\/li>\n<li>Min\/MaxLength<\/li>\n<li>Min\/MaxValue<\/li>\n<li>Defaults<\/li>\n<li>AllowedValues (array)<\/li>\n<li>AllowedPattern (regexp)<\/li>\n<li>No Echo (Boolean)\n<ul>\n<li>Used with Passwords<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre>Parameters:\r\n  SecurityGroupDescription:\r\n    Description: Security Group Description (Simple parameter)\r\n    Type: String\r\n  SecurityGroupPort:\r\n    Description: Simple Description of a Number Parameter, with MinValue and MaxValue\r\n    Type: Number\r\n    MinValue: 1150\r\n    MaxValue: 65535\r\n  InstanceType:\r\n    Description: WebServer EC2 instance type (has default, AllowedValues)\r\n    Type: String\r\n    Default: t2.small\r\n    AllowedValues:\r\n      - t1.micro\r\n      - t2.nano\r\n      - t2.micro\r\n      - t2.small\r\n    ConstraintDescription: must be a valid EC2 instance type.\r\n  DBPwd:\r\n    NoEcho: true\r\n    Description: The database admin account password (won't be echoed)\r\n    Type: String\r\n  KeyName:\r\n    Description: Name of an existing EC2 KeyPair to enable SSH access to the instances. Linked to AWS Parameter\r\n    Type: AWS::EC2::KeyPair::KeyName\r\n    ConstraintDescription: must be the name of an existing EC2 KeyPair.\r\n  SecurityGroupIngressCIDR:\r\n    Description: The IP address range that can be used to communicate to the EC2 instances\r\n    Type: String\r\n    MinLength: '9'\r\n    MaxLength: '18'\r\n    Default: 0.0.0.0\/0\r\n    AllowedPattern: (\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\/(\\d{1,2})\r\n    ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x\/x.\r\n  MyVPC:\r\n    Description: VPC to operate in\r\n    Type: AWS::EC2::VPC::Id\r\n  MySubnetIDs:\r\n    Description: Subnet IDs that is a List of Subnet Id\r\n    Type: \"List\"\r\n  DbSubnetIpBlocks:\r\n    Description: \"Comma-delimited list of three CIDR blocks\"\r\n    Type: CommaDelimitedList\r\n    Default: \"10.0.48.0\/24, 10.0.112.0\/24, 10.0.176.0\/24\"\r\n\r\nResources:\r\n  MyEC2Instance:\r\n    Type: \"AWS::EC2::Instance\"\r\n    Properties:\r\n      #we reference the InstanceType parameter\r\n      InstanceType: !Ref InstanceType\r\n      KeyName: !Ref KeyName\r\n      ImageId: \"ami-a4c7edb2\"\r\n      # here we reference an internal CloudFormation resource\r\n      SubnetId: !Ref DbSubnet1\r\n\r\n  MySecurityGroup:\r\n    Type: \"AWS::EC2::SecurityGroup\"\r\n    Properties:\r\n      GroupDescription: !Ref SecurityGroupDescription\r\n      SecurityGroupIngress:\r\n        - CidrIp: !Ref SecurityGroupIngressCIDR\r\n          FromPort: !Ref SecurityGroupPort\r\n          ToPort: !Ref SecurityGroupPort\r\n          IpProtocol: tcp\r\n      VpcId: !Ref MyVPC\r\n\r\n  DbSubnet1:\r\n    Type: AWS::EC2::Subnet\r\n    Properties:\r\n      VpcId: !Ref MyVPC\r\n      # the select function allows us to select across a list\r\n      CidrBlock: !Select [0, !Ref DbSubnetIpBlocks]\r\n  DbSubnet2:\r\n    Type: AWS::EC2::Subnet\r\n    Properties:\r\n      VpcId: !Ref MyVPC\r\n      # the select function allows us to select across a list\r\n      CidrBlock: !Select [1, !Ref DbSubnetIpBlocks]\r\n  DbSubnet3:\r\n    Type: AWS::EC2::Subnet\r\n    Properties:\r\n      VpcId: !Ref MyVPC\r\n      # the select function allows us to select across a list\r\n      CidrBlock: !Select [2, !Ref DbSubnetIpBlocks]\r\n<\/pre>\n<h3>How to reference a Parameter<\/h3>\n<ul>\n<li>Key: !Ref ParameterName\n<ul>\n<li>FromPort: !Ref SecurityGroupPort<\/li>\n<\/ul>\n<\/li>\n<li>You can use these for Resource Names as well!<\/li>\n<\/ul>\n<h3>How to create a Drop-Down list<\/h3>\n<pre>CiderBlock: !Select [0, !Ref DbSubnetIpBlocks]<\/pre>\n<ul>\n<li>!Select\n<ul>\n<li>Create a drop-down<\/li>\n<\/ul>\n<\/li>\n<li>[0,\n<ul>\n<li>Zero is the first index in the CommaDelimitedList array<\/li>\n<\/ul>\n<\/li>\n<li>!Ref DbSubnetIpBlocks]\n<ul>\n<li>Iis a CommaDelimitedList in the Parameters section<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><a name=\"how\"><\/a><\/p>\n<h2>How to Reference a Parameter<\/h2>\n<ul>\n<li>Fn::Ref in JSON<\/li>\n<li>!Ref in YAML<\/li>\n<li>You can also reference other elements within the template\n<ul>\n<li>Parameters<\/li>\n<li>Resource Names<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><a name=\"quiz\"><\/a><\/p>\n<h2>Quiz<\/h2>\n<h4>When should you use Parameters<\/h4>\n<ul>\n<li>Some inputs cannot be determined ahead of time<\/li>\n<li>You want to re-use your templates<\/li>\n<li>You want to prevent errors by restricting values to only valid values using types<\/li>\n<li><strong>All of the above<\/strong><\/li>\n<\/ul>\n<h4>What option for Parameter is useful if you pass in a sensitive value like a password<\/h4>\n<ul>\n<li>Constraint<\/li>\n<li><strong>NoEcho<\/strong><\/li>\n<li>Type<\/li>\n<\/ul>\n<h4>What is NOT an advantage of using Typed Parameters<\/h4>\n<ul>\n<li>It performs valixation to ensure the parameter&#8217;s values are valid<\/li>\n<li>It gives helpers and displays default values to the user when using the console.<\/li>\n<li><strong>It ensures your CloudFormation template will not fail.<\/strong><\/li>\n<\/ul>\n<p>Even if all the parameters are valid, your CF may still fail.\u00a0 Maybe the combination of paramters is not valid (subnets no belonging to the selected VPC for example).\u00a0 You cannot have constraints or sub parameters (yet).\u00a0 All in all, CloudFormation templates can fail even if using typed Parameters.\u00a0 The just greatly reduce the risk of errors.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.udemy.com\/aws-cloudformation-master-class\/learn\/v4\/t\/lecture\/8151200?start=0 Course Main Menu Section Menu Parameters Overview Theory &amp; Hands On How to Reference a Parameter Quiz &nbsp; Parameters Overview What are Parameters? Parameters are a way to provide inputs to your AWS CF template They are important to know about if: You want to reuse your templates across the company Some inputs cannot ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/wiki.thomasandsofia.com\/?p=1092\" 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-1092","post","type-post","status-publish","format-standard","hentry","category-cloudformation"],"_links":{"self":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/1092","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=1092"}],"version-history":[{"count":11,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/1092\/revisions"}],"predecessor-version":[{"id":1103,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/1092\/revisions\/1103"}],"wp:attachment":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}