AWS CloudFormation Flashcards

1
Q

What is AWS CloudFormation?

A

Infrastructure as Code.
CloudFormation is a declarative way of outlining your AWS Infrastructure, for any resources (most of them are supported)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Do you have to specify resource order in CF?

A

CloudFormation creates those for you, in the right order, with the exact configuration that you specify

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How CloudFormation Works?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you deploy tempaltes to CF?

A
  • manual way
  • automated way -> cli upload
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What the CF yaml file building blocks?

A
  1. Resources: your AWS resources declared in the template (MANDATORY)
  2. Parameters: the dynamic inputs for your template
  3. Mappings: the static variables for your template
  4. Outputs: References to what has been created
  5. Conditionals: List of conditions to perform resource creation
  6. Metadata
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the CF Resources?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does a CF Resource identifier look like?

A

AWS::aws-product-name::data-type-name, AWS::EC2::Instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the CF Parameters?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When to use a CF Parameter?

A
  • Ask yourself this:
  • Is this CloudFormation resource configuration likely to change in the future?
  • If so, make it a parameter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the CF Parameter settings?:

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to reference a CF Parameter in the tempalte?

A

!Ref {parameter}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are Pseudo Parameters in CF?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Mappings in CF?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe an example Mapping for CF

A

Mappings:
Mapping01:
Key01:
Name: Value01
Key02:
Name: Value02

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to use the Mapping is CF templates?

A
  • We use Fn::FindInMap to return a named value from a specific key
  • !FindInMap [ MapName, TopLevelKey, SecondLevelKey ]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are Outputs in CF?

A
  • The Outputs section declares optional outputs values that we can import into other stacks (if you export them first)!
  • It’s the best way to perform some collaboration cross stack, as you let expert handle their own part of the stack
  • You can’t delete a CloudFormation Stack if its outputs are being referenced by another CloudFormation stack
17
Q

What is Cross Stack Reference in a CF template?

A

Use !ImportValue {otherStackOutput} to reference other stack

18
Q

What are conditions used for in CF?

A
  • Conditions are used to control the creation of resources or outputs
    based on a condition.
  • Conditions can be whatever you want them to be, but common ones
    are:
  • Environment (dev / test / prod)
  • AWS Region
  • Any parameter value
  • Each condition can reference another condition, parameter value or
    mapping
19
Q

How to define a condition in a CF template?

A

Conditions:
CreateProdRes: !Equals [ !Ref EnvType, prod]

  • The intrinsic function (logical) can be any of the following:
  • Fn::And
  • Fn::Equals
  • Fn::If
  • Fn::Not
  • Fn::Or
20
Q

What can Fn:Ref retrive in CF templates?

A
  • Parameters => returns the value of the parameter
  • Resources => returns the physical ID of the underlying resource (ex: EC2 ID)
21
Q

What can Fn:GetAtt retrive in CF templates?

A

Attributes are attached to any resources you create

22
Q

Whats the usage of Fn::Join in CF templates?

A

Join values with a delimiter
!Join [ delimiter, [ coma-delimited list of values]]

23
Q

Whats the usage of Fn::Sub in CF templates?

A

Fn::Sub, or !Sub as a shorthand, is used to substitute variables from a
text. It’s a very handy function that will allow you to fully customize your
templates

24
Q

What are the Rollback options in CF?

A
  • Stack Creation Fails:
    – Default: everything rolls back (gets deleted). We can look at the log
    – Option to disable rollback and troubleshoot what happened
  • 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
25
Q

What are ChangeSets in CF?

A
  • When you update a stack, you need to know what changes before it happens for greater confidence
  • ChangeSets won’t say if the update will be successful
  • List the changes thats gonna happen by the update
26
Q

What are Nested stacks in CF?

A
  • 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
  • Nested stacks are considered best practice
  • To update a nested stack, always update the parent (root stack)
27
Q

What are StackSets in CF?

A
  • Create, update, or delete stacks across multiple accounts and regions with a single operation
  • Administrator account to create StackSets
  • Trusted accounts to create, update, delete stack instances from StackSets
  • When you update a stack set, all associated stack instances are updated throughout all accounts and regions.
28
Q

What is Drift in CF?

A

You can check what manual changes has been done compared to the original template.

29
Q

What are Stack Policies in CF?

A
  • During a CloudFormation Stack update, all update actions are allowed on all resources (default)
  • A Stack Policy is a JSON document that defines the update actions that are allowed on specific resources during Stack updates
  • Protect resources from unintentional updates
  • E.g: Allow updates on all resources except the ProductionDatabase