CloudFormation Flashcards
What does AWS CloudFormation do?
It declares and deploys infrastructure from a declarative template syntax.
What file formats are accepted by CloudFormation?
JSON & YAML
Name two key benefits over procedural scripting?
Infrastructure is now repeatable and versionable.
Name the CloudFormation concepts.
Stacks, change sets, permissions, templates, and instinct function
What is a CloudFormation Stack?
A stack represents a collection of resources to deploy and manage by AWS CloudFormation.
Does modifying the stack alter the underlying resources?
Yes, e.g. removing a resources from the stack and updating the stack, terminates the resource.
Can manual updates of resources in a stack cause future stack operations to fail?
Yes, because of inconsistencies in state that CloudFormation expects and the actual resource state.
What are CloudFormation Change Sets?
A change set is a description of the changes that will occur to a stack, should the changes be submitted.
When to use CloudFormation Change Sets?
to know what changes will occur to resources, before the update actually occurs.
What if Change Sets modifications are acceptable?
The change set can execute on the stack and implement the proposed modifications.
Under which role does CloudFormation function?
The user or role that invokes the stack action.
What to do if there is a need to restrict a user’s general permissions?
A service role can be provided, that the stack uses for the create, update, delete actions. It even has a default time out increase. Make sure that the role as a trust policy allows cloudformation.amazonaws,com to assume the role.
What permission are required by the user passing the service role to CloudFormation?
The iam:PassRole permission. Not needed for updates, though.
Where does the template have to be when submitting?
Local file or S3
Where is the template stored after submitting?
And what permissions are required for storage?
On S3 on our behalf. Required permissions for user or service role have to include:
cloudformation: CreateUploadBucket
s3: PutObject
s3: ListBucket
s3: GetObject
s3: CreateBucket
What is a high-level structure of template with all properties?
{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "String Description", "Metadata": { }, "Parameters": { }, "Mappings": { }, "Conditions": { }, "Transform": { }, "Resources": { }, "Outputs": { } }
What sections are required by CloudFormation in a template?
Only the “Resources” section is required.
What does the Metadata section do in a template?
Allows to provide structural details about the template. Metadata provided is accessible for reference in other sections and on EC2 instances being provisioned by CloudFormation.
"Metadata": { "ApplicationLayer": { "Description": "Information about resources in the app layer." }, "DatabaseLayer": { "Description": "Information about resources in the DB layer." } }
What does the Parameters section do in a template?
Can provide inputs to a template, either during creating the stack or updating the stack.
Which 2 things have to be provided for a parameter in a template?
A logical ID (aka Name) & a value, either default or provided during execution.
Can parameters outside a single template be referenced?
No.
Parameter in template example with reference:
This example defines a String parameter named InstanceTypeParameter with a default value of t2.micro. The parameter allows t2.micro, m1.small, or m1.large. The Allowed- Values section specifies what options you can select for this parameter in the AWS CloudFormation console. AWS CloudFormation will throw an error if you add a value not in AllowedValues.
“Parameters”: {
“InstanceTypeParam”: {
“Type”: “String”,
“Default”: “t2.micro”,
“AllowedValues”: [ “t2.micro”, “m1.small”, “m1.large” ],
“Description”: “Enter t2.micro, m1.small, or m1.large.
Default is t2.micro.”
}
}
Once you specify a parameter, you can use it within the template using the Ref intrinsic function. When AWS CloudFormation evaluates it, the Ref statement converts it to the value of the parameter.
“EC2Instance”: {
“Type”: “AWS::EC2::Instance”,
“Properties”: {
“InstanceType”: { “Ref”: “InstanceTypeParam” },
“ImageId”: “ami-12345678”
}
}
What parameter types does CloudFormation support?
String Number List of numbers Comma-delimited list AWS parameter types AWS Systems Manager Parameter Store (Systems Manager) parameter types (state key)
What does the Mappings section do in a template?
Creates rudimentary lookup tables that can be referenced in other sections of my template.
How to query values within a mapping?
Use the Fn::FindInMap intrinsic function.
What does the Conditions section do in a template?
Make use of intrinsic functions to evaluate multiple inputs against each other.
What does the Transforms section do in a template?
Allows to reuse templates within another template.
What are the two type of Transforms?
AWS::Include Transform
AWS::Serverless Transform
How does AWS::Include Transform work?
Acts as a tool to import snippets from Amazon S3 buckets into the template being developed.
At what template levels can AWS::Include Transform be called?
Top level, declared as “Transform”
{ "Transform" : { "Name" : "AWS::Include", "Parameters" : { "Location" : "s3://MyAmazonS3BucketName/MyFileName.json" } } }
and in nested sections declared as “Fn::Transform”
{ "Fn::Transform" : { "Name" : "AWS::Include", "Parameters" : { "Location" : "s3://MyAmazonS3BucketName/MyFileName.json" } } }
How does AWS::Serverless Transform work?
Converts AWS Serverless Application Model (SAM) templates to valid CloudFormation templates.
SAM can be used with Lambda, API Gateway, and DynamoDB.
What does the Resources section do in a template?
Declares the actual resources to be provisioned and their properties. Each resource needs a logical ID.
{ "Resources": { "MyBucket": { "Type": "AWS::S3::Bucket", "Properties": { "BucketName": "MyBucketName1234" } } } }