CloudFormation Flashcards
What is CloudFormation?
- Infrastructure as Code
- Code that can be deployed and is written to create / update / delete infrastructure
Is there a cost for using CloudFormation?
No. Only the underlying services.
High Level - How does CloudFormation work?
- Templates have to be uploaded in S3 and then referenced in CloudFormation.
- To update a template, a new version must be uploaded to AWS (cannot edit existing one directly).
What are the 2 main ways to deploy CloudFormation templates?
- Manually
- Automated (recommended)
Describe manual deploys in CloudFormation
- Edit templates in the CloudFormation designer
- Use the console to input parameters etc.
Describe the high level overview of deploying CloudFormation through automation.
- Edit templates in a YAML file.
- Use the AWS CLI to deploy the templates.
- Recommended way in order to fully automate flow.
List the 6 main building blocks for CloudFormation.
- Resources (Required)
- Parameters
- Mappings
- Outputs
- Conditionals
- Metadata
The exam will not expect you to write CloudFormation templates, but it will expect you to be able to READ CloudFormation templates. What language should you be familar with so that you can read and understand CloudFormation?
YAML
Can Resources be dynamically created using CloudFormation?
No. Resources in the CloudFormation Template must be declared.
Is every AWS resource supported through CloudFormation.
No, but almost. Mostly smaller services that are not yet addressed and you can work around that using AWS Lambda Custom Resources.
What are CloudFormation parameters?
- Parameters are a way to provide inputs to your AWS CloudFormation templates.
- Parameters are extremely powerful, controlled, and can prevent errors from happening in your templates thats to types.
When should you use CloudFormation parameters?
- If the CloudFormation resource is likely to change in the future.
- By making a parameter you will not have to re-load a template to change its content.
How do you reference a parameter in CloudFormation?
- The Fn::Ref function can be leverage to reference parameters.
- The shorthand for this in YAML is !Ref
- Parameters can be referenced anywhere in the template.
How can you get the account ID using a CloudFormation template?
- CloudFormation has something called pseudo parameters.
- These can be used at anytime and are enabled by default.
- One of these pseudo parameters in AWS::AccountId
What are CloudFormation Mappings?
- Mapping are fixed variables with the CloudFormation template.
- Handy to differentiate between different environments (dev vs prod), regions, AMI types etc.
- All values are hardcoded in the template.
What is the difference between CloudFormation parameters & mappings?
Use Mapping when you know values in advanced and reosurces will most likely NOT change. Those values can be turned into variables (region, AMI, enviroment etc. ).
Use Parameters when a resource configuration is likely to change in the future.
What happens if you delete a stack created by CloudFormation?
Deleting a stack deletes every single artifact that was created by
CloudFormation.
How are CloudFormation stacks identified?
Stacks are identified by a name.
What are CloudFormation outputs?
- The outputs section in a CloudFormation template declares optional outputs that must first be exported and then can be imported into other stacks.
- Allows for collaboration across stacks.
What happens if you delete a stack that has declared exported outputs?
That stack cannot be deleted as long as exported outputs are being used in other stacks.
What is a CloudFormation Cross Stack Reference?
When a stack references the output(s) of another stack.
How are CloudFormation outputs imported into another stack?
- Fn::ImportValue
- In YAML this is : !ImportValue [Value Variable Name]
How are conditions used in CloudFormation?
- Conditions are used to control the create of resources or outputs.
- Example: Conditions can be based on Environment, Region etc.
Hoe are conditions defined in CloudFormation?
There is a conditions section the YAML file that can use any common logical operators.
What are the five conditional (logical) operators that can be used in CloudFormation?
- Fn::And
- Fn::Equals
- Fn::If
- Fn::Not
- Fn::Or
Other then CloudFormation conditional values, what are six Instrinic functions to know?
All six are prepended with Fn::
- Ref
- GetAtt
- FindInMap
- ImportValue
- Join
- Sub
Fn::Ref
- References a parameter (returns the value of the paramter) or
- references a resource (returns the physical ID of the underlying resource.
- YAML = !Ref
Fn::GetAtt
- Returns a value for a specified attribute of the defined type.
- Example for EC2 you can to Fn::GetAtt AvailabilityZone
Fn::FindInMap
- Accesses mapped values - returns a named value from a specific key
- YAML = !FindInMap
Fn::ImportValue
- Import values are values that have been exported from another CloudFormation template.
- YAML = !ImportValues
Fn::Join
Join values with a delimiter
Example:
!Join [”:” , [a,b,c] ] returns ‘a:b:c’
Fn::Sub
- Used to substitute variable from text.
- Allows you to fully customize your templates.
- YAML = !Sub
What is a cross stack and when are they useful?
- Cross-stack references let you use a layered or service-oriented architecture. Instead of including all resources in a single stack, you create related AWS resources in separate stacks; then you can refer to required resource outputs from other stacks.. (Example, VPC stack, ELB Stack etc.).
- Helpful when stacks have different lifecycles.
- Use outputs export and importValue.
In CloudFormation, what is a nested stack, and when are they useful?
- Nested stacks are stacks created as part of other stacks.
- You create a nested stack within another stack by using the AWS::CloudFormation::Stack resource.
- Helpful when components must be reused
In CloudFormation, what are StackSets?
- StackSets all you to create, update, or delete stacks across multiple accounts and regions with a single operation.
- When you update a stack set, all associated stack instances are updated throughout all accounts and regions.