AWS CloudFormation Essentials
CloudFormation templates can be defined using YAML or JSON
CloudFormation Components
CloudFormation consists of 9 components. Only Resources is mandatory
- AWSTemplateFormatVersion:
Future proofs the template from future features and behaviors of CloudFormation. Or if the format of the template changes. - Description:
Optional however it must come right after AWSTemplateFormatVersion if you intend to use it. - Metadata:
Optional multipurpose. - Parameters:
Define inputs - Mappings:
Include conditional data
- Conditions:
Similar to a switch IF statement - Transform:
Mainly used in serverless applications - Resources:
Only required component.
Here logical resources are define which translate into physical resources once the template has been executed.
If you do not utilize the Name parameter of a logical resource it will incorporate the logic resources name. - Outputs:
CloudFormation Skeleton
YAML
---
AWSTemplateFormatVersion: "2010-09-09"
Description:
this template does something
Metadata:
template metadata
Parameters:
set of parameters
Mappings:
set of mappings
Conditions:
set of conditions
Transform:
set of transforms
Resources:
set of resources
Outputs:
set of outputs
JSON
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "this template does something",
"Metadata" : {
},
"Parameters" : {
},
"Mappings" : {
},
"Conditions" : {
},
"Transform" : {
},
"Resources" : {
},
"Outputs" : {
}
}
Intrinsic Functions
Functions that assist in assigning values to properties that are not available until runtime.
Fn:GetAZs
Fn:Base64
Fn:Cidr
Fn:FindInMap
Fn:GetAtt
Fn:ImportValue
Fn:Join
Fn:Select
Fn:Split
Fn:Sub
Fn:Transform
Ref
Condition Functions
Conditional create stack resources
Fn:And
Fn:Equals
Fn:If
Fn:Not
Fn:Or
Related
Links
- https://aws.amazon.com/cloudformation/
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/CHAP_TemplateQuickRef.html
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros.html
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/create-reusable-transform-function-snippets-and-add-to-your-template-with-aws-include-transform.html