CloudFormation Flashcards
What is CloudFormation?
CloudFormation is a declarative way of outlining your AWS Infrastructure, for any resources (most of them are supported).
In what order does CloudFormation create the resources defined in the stack?
The order in the file is not important. CloudFormation creates the resources for you in the right order with the exact configuration that you specify
What is provided by CloudFormation to help you with cost insights?
Each resource within the stack is tagged with an identifier so you can easily see how much a stack costs you
What saving strategy can you use in CloudFormation?
In Dev i.e., you could automation deletion of templates at 5 PM and recreated at 8 AM, safely
Where are CloudFormation templates stored?
In S3
What you need to do to update a CloudFormation template?
To update a template, we can’t edit previous ones. We have to reupload a new version of the template to AWS
What happens when you delete a CloudFormation stack?
Deleting a stack deletes every single artifact that was created by CloudFormation
What are the CloudFormation template components?
- Resources
- Parameters
- Mappings
- Outputs
- Conditionals
- Metadata
What are the CloudFormation template helpers?
- References
- Functions
What CloudFormation component is mandatory?
Resources
What is CloudFormation Resource identifiers format?
AWS::aws-product-name::data-type-name
What is a CloudFormation Resource?
- Resources are the core of your CloudFormation template (MANDATORY)
- They represent the different AWS Components that will be created and configured
Can I create a dynamic amount of resources in CloudFormation?
No, you can’t. Everything in the CloudFormation template has to be declared. You can’t perform code generation there
Is every AWS Service supported by CloudFormation?
o Almost. Only a select few niches are not there yet
o You can work around that using AWS Lambda Custom Resources
What is a CloudFormation Parameter?
Parameters are a way to provide inputs to your AWS CloudFormation template
How many times can you use a CloudFormation Parameter?
Parameters can be used anywhere in a template
If a CloudFormation resource configuration is likely to change in the future, what you should do?
make it a parameter, you won’t have to re-upload a template to change its content
What can you use if some inputs cannot be determined ahead of time in CloudFormation?
parameters
How can you prevent errors from happening in your CloudFormation Parameters?
Using types
What are the CloudFormation Parameter’s types?
o String o Number o CommaDelimitedList o List o AWS Parameter
What are CloudFormation Pseudo Parameters?
- AWS offers us pseudo parameters in any CloudFormation template.
- These can be used at any time and are enabled by default
What are most important CloudFormation Pseudo Parameters?
- accountId
- region
- stackId
- stackName
What is a CloudFormation Mapping?
- Mappings are fixed, hardcoded variables within your CloudFormation Template.
- They’re very handy to differentiate between different environments (dev vs prod), regions (AWS regions), AMI types, etc.
When would you use CloudFormation mappings vs parameters?
• Mappings are great when you know in advance all the values that can be taken and that they can be deduced from variables such as o Region o Availability Zone o AWS Account o Environment (dev vs prod) o Etc…
What is a CloudFormation Output?
The Outputs section declares optional outputs values that we can import into other stacks
What you must do in your CloudFormation Output to allow another another stack to import it?
Define the Export key which it is optional, but without it you will not be able to import this resource in another template
In what case could be very useful to define CloudFormation Outputs?
They’re very useful for example if you define a network CloudFormation, and output the variables such as VPC ID and your Subnet IDs
When you could not delete a CloudFormation stack?
You can’t delete a CloudFormation Stack if its outputs are being referenced by another CloudFormation stack
What is a CloudFormation Condition?
Conditions are used to control the creation of resources or outputs based on a condition
What are common CloudFormation Conditions?
Conditions can be whatever you want them to be, but common ones are:
o Environment (dev / test / prod)
o AWS Region
o Any parameter value
What can be referenced by a CloudFormation Condition?
Each condition can reference another condition, parameter value or mapping
What are the CloudFormation Condition functions?
The intrinsic function (logical) can be any of the following: o Fn::And o Fn::Equals o Fn::If o Fn::Not o Fn::Or
What can be applied to CloudFormation Conditions?
Conditions can be applied to resources / outputs / etc…
What are the CloudFormation must known intrinsic Functions?
- Fn::Ref
- Fn::GetAtt
- Fn::FindInMap
- Fn::ImportValue
- Fn::Join
- Fn::Sub
- Condition Functions
What is for the CloudFormation function Fn::Ref?
The Fn::Ref function can be leveraged to reference
o Parameters
o Resources
What is returned when your use the function !ref to reference a resource in CloudFormation?
returns the physical ID of the underlying resource (ex: EC2 ID)
What is for the CloudFormation function Fn::GetAtt?
Attributes of another resources can be attached to any resources you create, i.e.:
!GetAtt RESOURCE_NAME.AvailabilityZone
What is for the CloudFormation function Fn::FindInMap?
We use Fn::FindInMap to access Maping values to return a named value from a specific key
What is the CloudFormation function Fn::FindInMap nomenclature?
- !FindInMap [ MapName, TopLevelKey, SecondLevelKey ]
Explain how does work the CloudFormation function Fn::FindInMap
Supposing you have this:
Mappings:
— RegionMap:
—— us-east-1:
——— “32”: “ami-43jn34k”
——— “64”: “ami-fwfweke”
—— us-west-1
…
You can use
- !FindInMap [RegionMap, !Ref “AWS::Region”, 32]
What is for the CloudFormation function Fn::ImportValue?
To Import values that are exported in other templates
What is for the CloudFormation function Fn::Join?
Join values with a delimiter
What is the CloudFormation function Fn::Join nomenclature?
- !Join [delimiter, [comma-delimited list of values]]
- !Join [”:”, [a,b,c]] = a:b:c
What is for the CloudFormation function Fn::Sub?
Is used to substitute variables from a text. String must contain ${VariableName} and will substitute them
What happens when a CloudFormation Stack Creation Fails?
everything rolls back (gets deleted). We can look at the log
What can you do to troubleshoot a CloudFormation Stack Creation Fail?
Option to disable rollback and troubleshoot what happened
What happens when a CloudFormation Stack Update Fails?
The stack automatically rolls back to the previous known working state. Ability to see in the log what happened and error messages
When you update a CloudFormation stack, you need to know what changes before it happens for greater confidence, what helps you with it?
ChangeSets
What will not help you with a CloudFormation ChangeSet?
won’t say if the update will be successful
What are and what allow you to do CloudFormation Nested Stacks?
- Nested stacks are stacks as part of other stacks
* They allow you to isolate repeated patterns / common components in separate stacks and call them from other stacks
What you must do to update CloudFormation Nested Stack?
To update a nested stack, always update the parent (root stack)
When you use CloudFormation Cross vs Nested Stacks?
Cross Stacks
o Helpful when stacks have different lifecycles
o Use Outputs Export and Fn::ImportValue
o When you need to pass export values to many stacks (VPC Id, etc.…)
Nested Stacks
o Helpful when components must be re-used
o Ex: re-use how to properly configure an Application Load Balancer
o The nested stack only is important to the higher-level stack (it’s not shared)
What is a CloudFormation StackSet?
Create, update, or delete stacks across multiple accounts and regions with a single operation