CLOUDFORMATION Flashcards
Ref! vs GetAtt Function
Ref! references: To access Physical or Logical resource. eg, InstanceID.
while
GetAtt: To access attributes(certain elements )within a logical or physical resource. eg, Public IP, DNS name. Inner details
fn::Join vs Split
To concatenate two or more attributs. eg fn::join: [https://,instaceID,DNSname].
Split opposite of join.
Fn:GetAZ and Fn::Select
Fn::GetAZ is used for returns AZ List from a region.
Fn::Select[index] is used to pick/accept an object from the AZ list
eg,
**Deleted subnets from vpc invalidates an AZ from being returned. **
Fn::BAse64 vs Fn::Sub!
Fn::BAse64 accepts normal text and passes the converted Base64 encoded text.
Fn::Sub! allows replacement of variables
AWS::Region
AWS::Region will always resolve to the Particular Region the stack is being uploaded to
!FindInMap function
in the Below Map Block,
Mappings:
RegionMap:
us-east-1:
HVM64: “ami-Off8a91507f77f867”
HMG2: “ami-0a584ac55a7631c0c”
us-west-1:
HVM64: “ami-Obdb828fd58c52235”
HMG2: “ami-066ee5fd4a9ef77f1”
eu-west-1:
HVM64: “ami-047bb4163c506cd98”
HVMG2: “ami-31c2f645”
with the following function call:
!FindInMap [ “RegionMap”, !Ref ‘AWS::Region’,HVM64”]
- The “RegionMap” will return = call the Map Block
- The !Ref ‘AWS::Region will return = Current Region
- *'’HVM64’’ *will return the Value of the Key/Pair containing HVM64.
Fn::Mappings
Is used to draw a Lookup Table that can be referenced or called with the !FindInMap to return a value from the Lookup table
Fn:Outputs
in the below Block
Outputs:
WordpressURL:
Description: “Instance Web URL”
Value: !Join [ ‘’, [ ‘https: //’, !GetAtt. Instance.DNSName ]
The Above block will output the concatenated Value of https:// + the instance DNS Name
Note
Note that the GetAtt returns an attribute from a resource(Instance)
Note also that insamuch as the Outputs block is optional, the Description line is very important
Portable vs NonPortable
Non Portable: HardCoded resources that can not be replicated across AWS or another region.
eg a stack containing a hard coded S3 Bucket name, a template containing an AMI(which is region specific
Parameter Best Practices
- use as few as Possible Parameters
- Provide Default Values for Parameters
what would this do in a buckets resource block?‘AWS::S3::Bucket’
Cloudformation will create a bucket with a unique name for you
DependsOn
Without this specification, Cloudformation deploys resources in its most convenient order, which might simply be random.
With the DependsOn attribute, you can specify that the creation of a specific resource follows another. When you add a DependsOn attribute to a resource, that resource is created only after the creation of the resource specified in theDependsOn attribute.
the DependsOn atribute is used for resource creations that will malfunction if the order of creation is not explicitly defined. Eg, Userdata must not run until EC2 instance is fully up and running, deleting vpc before Elastic IP
This helps to implement orderliness in resource deployment to ensure dependencies are run exactly when they should.
Cfn-Signal
A tool Added to resource block as utility to an instance during bootstrapping. It supplies utility signals to the required service
Creation Policy
Creation Policy is a tool that adds signal requirements for a resource to be either deployed or rolled back. It integrates with Cfn-signal which is the supplier of the signal data to be used. It Basically handles the wait schedule before the next deployment, eg in an ASG; it can require 3 signals within 15mins before next instance is deployed. It depends on Cfn-signal for the alarm.
Wait condition
Is a dataflow resource that works like Creation Policy but as a resource on it’s own. This works with other services that are not EC2 instances. It waits for signals from various sources within a specified time-out.
Wait condition can receive data (JSON) from a process and forward it to appropriate process that are requesting. Other processes can request the Wait condition’s output via !GetAtt waitcondition.data. It’s output is a Pre-signed URL which is useable by any other application even a non- AWS application.