aws cloudformation intrinsic functions and mappings
TRANSCRIPT
![Page 1: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/1.jpg)
AWS CloudFormationIntrinsic Functions and Mappings
Managing Windows instances in the Cloud
![Page 2: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/2.jpg)
Sponsors
![Page 3: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/3.jpg)
Presented by Adam Book from
Find me on LinkedIn
CloudFormation Deep Dive
![Page 4: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/4.jpg)
CloudFormation Review
AWS CloudFormation Allows you to build Infrastructure as code using templates which are constructed from json.
![Page 5: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/5.jpg)
CloudFormation Template
There are 8 sections of a Cloud formation template, most of which are optional
Format Version (optional)
Description (optional)
Metadata (optional)
Mappings (optional)
Parameters(optional)
Conditions(optional)
Resources (required)
Outputs(optional)
![Page 6: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/6.jpg)
CloudFormation Best Practice
For more infohttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html
As you use Cloud Formation make sure you follow the best practices for success
• Do Not Embed Credentials in You Templates• Use AWS-Specific Parameter Types• Use Parameter Constraints • Validate Templates Before Using them • Manage All Stack Resources Through AWS Cloud Formation
![Page 7: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/7.jpg)
CloudFormationIntrinsic FunctionsFunction OverviewFn::Base64 returns the Base64 representation of the input string (user data)
Fn::FindInMap returns the value corresponding to keys in a two-level map that is declared in the Mappings section
Fn::GetAtt returns the value of an attribute from a resource in the template.
Fn::GetAZs returns an array that lists Availability Zones for a specified region.
Fn::Join appends a set of values into a single value, separated by the specified delimiter.
Fn::Select returns a single object from a list of objects by index.
Ref returns the value of the specified parameter or resource.
![Page 8: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/8.jpg)
CloudFormationMappings
The Mappings section is optional but is matches a key to a corresponding set of named values. If you want to set values based on region, you can create a mapping that uses the key as the name and then contains the values you want to specify for each region.
You cannot include parameters, pseudo parameters, or intrinsic functions in the Mappings section.
![Page 9: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/9.jpg)
CloudFormationMappings - cont. "Mappings" : { "RegionMap" : { "us-east-1" : { "32" : "ami-6411e20d"}, "us-west-1" : { "32" : "ami-c9c7978c"}, "eu-west-1" : { "32" : "ami-37c2f643"}, "ap-southeast-1" : { "32" : "ami-66f28c34"}, "ap-northeast-1" : { "32" : "ami-9c03a89d"} } }
![Page 10: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/10.jpg)
CloudFormationMappings - cont. "asgApp": { "MinSize" : { "value": "2" }, "MaxSize" : { "value": "2" }, "DesiredCapacity" : { "value": "2" }, "HealthCheckType" : { "value": "EC2" }, "TerminationPolicies" : { "value": "OldestInstance" } }
![Page 11: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/11.jpg)
CloudFormationMappings - cont.
"asgAppA": { "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { "AvailabilityZones" : { "Ref": "AZs" }, "VPCZoneIdentifier" : { "Ref": "PrivateAPPSubnets" }, "LaunchConfigurationName" : { "Ref": "LaunchConfig" }, "MinSize" : { "Fn::FindInMap": [ "asgApp", "MinSize", "value" ] }, "MaxSize" : { "Fn::FindInMap": [ "asgApp", "MaxSize", "value" ] }, "DesiredCapacity" : { "Fn::FindInMap": [ "asgApp", "DesiredCapacity", "value" ] }, "HealthCheckType" : { "Fn::FindInMap": [ "asgApp", "HealthCheckType", "value" ] }, "TerminationPolicies" : [{ "Fn::FindInMap": [ "asgApp", "TerminationPolicies", "value" ] }],
![Page 12: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/12.jpg)
Fn::FindInMap
"Resources" : { "myEC2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "32"]}, "InstanceType" : "m1.small" } } } }
This function performs lookups, it accepts a ‘mappings’ object on of one or two keys and then returns a value
For more infohttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html
![Page 13: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/13.jpg)
Fn::Base64
{ "Fn::Base64" : ”apt-get update –y " }
This function accepts plain text and converts it to Base 64
For more infohttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-base64.html
![Page 14: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/14.jpg)
Fn::Join
"Outputs" : { "URL" : { "Description" : "The URL of your demo website", "Value" : { "Fn::Join" : [ "", [ "http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}]]} } }
This can be used to concatenate various components to produce things such as a URL.
For more infohttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html
![Page 15: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/15.jpg)
Fn::GetAtt
Some examples of attributes that can be called are:• EC2 -> PrivateIp• EC2-> PublicIp• ElasticLoadBalancing -> DNSName• IAM::Group -> ARN • S3 Bucket -> DomainName • Simple AD -> Alias
As you dynamically create items in your Cloud Formation templates , you may need to use some of the Attributes after they are created.
For more infohttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html
![Page 16: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/16.jpg)
Fn::GetAtt
"MyEIP" : { "Type" : "AWS::EC2::EIP", "Properties" : { "InstanceId" : { "Ref" : "MyEC2Instance" } } }
“Fn:GetAtt” :[ “MyEIP”, “AllocationId” ]
As you dynamically create items in your Cloud Formation templates
For more infohttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html
![Page 17: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/17.jpg)
Fn::GetAZs
{ "Fn::GetAZs" : "us-east-1" }
{ "Fn::GetAZs" : { "Ref" : "AWS::Region" } }
The intrinsic function Ref returns to value of the specified parameter or resource.
For more infohttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-select.html
NOTE: You can use the Ref function in the Fn::GetAZz function.
![Page 18: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/18.jpg)
Fn::Select
{ “Fn::Select” : [ “0”, {”Fn::GetAZs” : “”} ] }
Selects a single object from a list of object and can be paired with other functions such as Fn::GetAZs
For more infohttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-select.html
The output is the first Availablity zone in the region where the template is applied.
Replacing the 0 with a 1 would select the second Availability Zone
![Page 19: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/19.jpg)
Fn::Ref
"MyEIP" : { "Type" : "AWS::EC2::EIP", "Properties" : { "InstanceId" : { "Ref" : "MyEC2Instance" } } }
The intrinsic function Ref returns to value of the specified parameter or resource.
For more infohttp://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html
![Page 20: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/20.jpg)
Cloud Formation Templates Real World Examples
Photo curtesyof Stephen Radford via http://snap.io
![Page 21: AWS CloudFormation Intrinsic Functions and Mappings](https://reader033.vdocument.in/reader033/viewer/2022052219/5876fec71a28abf3398b6dc9/html5/thumbnails/21.jpg)
Questions?
Image by http://www.gratisography.com/