Section 10: AWS CloudFormation Flashcards
Why is manual work (clicking in the consoleโฆ) not very good?
Hard to reproduce
What is CloudFormation?
A declarative way of outlining your AWS
Infrastructure, for any resources
Which resources are supported by AWS CloudFormation?
Most of them
Do you have to specify a creation order for the resources in a CloudFormation template?
No, you write your templates in a declarative way and CloudFormation will take care of creating the resources in the right order
In what file type can you write CloudFormation templates?
JSON or YAML
What does IaC stand for?
Infrastructure as Code
What are the benefits of IaC
No manual work
You get version control just like regular code
You can review your infrastructure easily through code
You get easy deployments
What are the cost of CloudFormation?
No additional cost
You only pay for the underlying resources
How can you estimate the cost of a CloudFormation stack?
By using the provided tool for that purpose in CloudFormation
What is a good savings strategy for development environments when using CloudFormation?
You can automate the deletion of templates at 5PM and creation of templates at 8AM (So that you donโt pay for dev environment when you are not using it at night)
What are the productivity benefits of CloudFormation?
Ability to create and destroy stacks on the fly
You get automated generation of diagrams
No need to figure out ordering and orchestration of your infrastructure
How to do seperation of concerns with CloudFormation?
Create many stacks for many apps and many layers
Where must CloudFormation templates be uploaded to in order to be able to use them?
In S3
How can you update a CloudFormation stack?
By reuploading a new version to AWS
How are stacks identified in CloudFormation?
By name
What happens to the underlying resources when you delete a stack?
They get deleted
What is the manual way of deploying a CloudFormation stack?
By editing templates in the CloudFormation Designer
Using the console to input parameters
What is the automated way of deploying a CloudFormation stack?
Editing templates in a YAML file
Using the CLI to deploy the templates
What is the recommended way to deploy CloudFormation templates?
The automated way
What are the building blocks of CloudFormation templates?
Templates components
Templates helpers
What are the CloudFormation templates helpers?
References
Functions
What are the CloudFormation templates components?
Resources Parameters Mappings Outputs Conditionals Metadata
Which CloudFormation templates component is mandatory?
Resources
What does YAML stand for?
YAML Ainโt Markup Language (A recursive acronym)
What can be in a YAML file?
Key value pairs Nested objects Arrays Multi line string Comments
What do key value pairs look like in YAML?
key: value
What do nested objects look like in YAML?
key:
param1: value1
param2: value2
otherKey: otherValue
What do arrays look like in YAML?
keys:
- โoneโ
- โtwoโ
- โthreeโ
What do multi line string look like in YAML?
myString: |
I am a
multiline string
What do comments look like in YAML?
This is a comment
What are resources in a CloudFormation template?
AWS Components/Resources that will get created and configured
What is the form of resource types identifiers?
AWS::aws-product-name::data-type-name
Can you create a dynamic amount of resources directly in a CloudFormation template?
No, CloudFormation templates are declarative, everything has to be declared
What are the two fields that every resource declared in a CloudFormation template must contain?
Type: AWS::XXX:XXX
Properties:
Property1: value1
Property2: value2
How to know what properties are available on what AWS resources types?
By looking at the CloudFormation documentation for the corresponding AWS resource
What are CloudFormation parameters?
A way to provide inputs to your AWS CloudFormation
template
When should you use CloudFormation parameters?
When a certain resource configuration is likely to change in the future
What are the settings of a CloudFormation parameter?
Type Description ConstraintDescription Min/MaxLenght Min/MaxValue Default AllowedValues (array) AllowedPattern (regexp) NoEcho (bool)
What are the available types of CloudFormation parameters?
String Number List CommaDelimitedList AWS Parameter
What is the โAWS parameter typeโ used for in CloudFormation parameters?
A way to help catch invalid values - match against existing values in the AWS account
What can you do to make sure a CloudFormation parameter matches a certain pattern?
Define the AllowedPattern parameter setting
What can you do to make sure a CloudFormation parameter matche is between a certain range?
Define the Min/MaxLenght for String
Define the Min/MaxValue for Number
What does the parameter setting NoEcho does?
It displays the parameter value as *** in the console in order to mask the value
How to reference a parameter in a CloudFormation template?
By using the Fn::ref function
What is an other/cleaner way of using a Fn::ref function?
By using the !ref syntax
What are pseudo parameters?
Parameters directly provided by AWS
How to reference the account id in a CloudFormation template?
By using the AWS::AccountId pseudo parameter like so:
!ref โAWS::AccountIdโ
What are the available pseudo parameters in CoudFormation?
AWS::AccountId AWS::NotificationARNs AWS::NoValue AWS::Partition AWS::Region AWS::StackId AWS::StackName AWS::URLSuffix
What does the AWS::NoValue pseudo parameters give us
They allow us to removes the corresponding resource property when specified as a return value in the Fn::If intrinsic function
DBSnapshotIdentifier: Fn::If: - UseDBSnapshot - Ref: DBSnapshotName - Ref: AWS::NoValue
What are mappings?
Mappings are fixed variables within your CloudFormation Template
What are they good for?
Handy to differentiate between env, regions, AMI types, etc.
Where are mappings value defined?
Within the template
When should you use mappings instead of parameters?
When you know in advance all the values that can be used and the circumstances when each value must be used
Which are safer, mappings or parameters?
Mappings
How to define mappings in your template?
In the Mappings section of your template, you must define the mapping, the top level keys and second levels keys
For example:
Mappings: MyFirstMapping: TopLevelKey1: SecondLevelKey1: SecondLevelKey2: TopLevelKey2: SecondLevelKey1: SecondLevelKey2:
How to access mapping values?
With the Fn::FindInMap function
!FindInMap [MapName, TopLevelKey, SecondLevelKey]
What are Outputs in CloudFormation?
Optional values that can be imported into other stacks
Where can you view CloudFormation outputs?
In the AWS console or using the AWS CLI
How are outputs useful?
They are useful when you have something like a network CloudFormation stack and you want to output the variables such as VPC ID and Subnet IDs
What happens if you try to delete a stack which outputs are used by another stack
It wonโt be able to delete
How to import values from the outputs of another CloudFormation stack?
By using the Fn::ImportValue function
What are conditions used for in CloudFormation?
Used to control the creation of resources or outputs based on a condition
What are some common conditions which are used in a CloudFormation template based on?
Environment
Region
Can conditions reference other conditions
Absolutely
How/Where do you define conditions in a CloudFormation template
In the Conditions section of the template, for example:
Conditions:
CreateProdResource: !Equals [!Ref EnvType, prod]
How to use a condition when creating a resource?
You use the Condition field like so:
Resources:
MyResource:
Type: โAWS::PRODUCT::TYPEโ
Condition: MyCondition
What does the Fn::GetAtt allows you to get?
Available attributes that are attached to any resources you create (See the docs to know which attributes are available)
What does the Fn::Ref function allow you to get?
Parameters (Value of the parameters)
Resources (ID of the underlying resource)
What does the Fn::Join function allow you to do?
Join values with a delimiter, for example:
!Join [โ:โ, [a,b,c]]
This create โa:b:cโ
What does the Fn::Sub function allow you to do?
Substitute variables from a text, for example:
Name: !Sub
- www.${Domain}
- { Domain: !Ref RootDomainName }
What are the available intrinsic condition functions in CloudFormation?
Fn::And Fn::Equals Fn::If Fn::Not Fn::Or
What happens by default if a stack creation fails?
Everything rolls back (get deleted since itโs a creation)
What happens by default if a stack update fails?
Everything rolls back to the previous known working version