AWS CloudFormation Flashcards
What is AWS CloudFormation?
Infrastructure as Code.
CloudFormation is a declarative way of outlining your AWS Infrastructure, for any resources (most of them are supported)
Do you have to specify resource order in CF?
CloudFormation creates those for you, in the right order, with the exact configuration that you specify
How CloudFormation Works?
- Templates have to be uploaded in S3 and then referenced in CloudFormation
- To update a template, we can’t edit previous ones. We have to reupload a new version of the template to AWS
- Stacks are identified by a name
- Deleting a stack deletes every single artifact that was created by CloudFormation.
How can you deploy tempaltes to CF?
- manual way
- automated way -> cli upload
What the CF yaml file building blocks?
- Resources: your AWS resources declared in the template (MANDATORY)
- Parameters: the dynamic inputs for your template
- Mappings: the static variables for your template
- Outputs: References to what has been created
- Conditionals: List of conditions to perform resource creation
- Metadata
What are the CF Resources?
- Resources are the core of your CloudFormation template (MANDATORY)
- They represent the different AWS Components that will be created and configured
- Resources are declared and can reference each other
- AWS figures out creation, updates and deletes of resources for us
How does a CF Resource identifier look like?
AWS::aws-product-name::data-type-name, AWS::EC2::Instance
What are the CF Parameters?
- Parameters are a way to provide inputs to your AWS CloudFormation template
- You want to reuse your templates across the company
- Some inputs can not be determined ahead of time
When to use a CF Parameter?
- Ask yourself this:
- Is this CloudFormation resource configuration likely to change in the future?
- If so, make it a parameter
What are the CF Parameter settings?:
- Type:
– String
– Number
– CommaDelimitedList
– List<Type>
-- AWS Parameter (to help catch invalid values – match against existing values in the AWS Account)</Type> - Description
- Constraints
- ConstraintDescription (String)
- Min/MaxLength
- Min/MaxValue
- Defaults
- AllowedValues (array)
- AllowedPattern (regexp)
- NoEcho (Boolean)
How to reference a CF Parameter in the tempalte?
!Ref {parameter}
What are Pseudo Parameters in CF?
- AWS offers us pseudo parameters in any CloudFormation template.
- These can be used at any time and are enabled by default
1. AWS::AccountId
2. AWS::NotificationARNs
3. AWS::NoValue
4. AWS::Region
5. AWS::StackId
6. AWS::StackName
What are Mappings in CF?
- Mappings are fixed variables within your CloudFormation Template.
- They’re very handy to differentiate between different environments (dev vs prod), regions (AWS regions), AMI types, etc
- All the values are hardcoded within the template
Describe an example Mapping for CF
Mappings:
Mapping01:
Key01:
Name: Value01
Key02:
Name: Value02
How to use the Mapping is CF templates?
- We use Fn::FindInMap to return a named value from a specific key
- !FindInMap [ MapName, TopLevelKey, SecondLevelKey ]