Advanced 20 min read

AWS CloudFormation Templates

By the end of this lesson, you'll be able to:

  • Explain what AWS CloudFormation is and the template-to-stack relationship
  • Read a simple CloudFormation template written in YAML, including its Resources section
  • Distinguish a CloudFormation template (a definition) from a stack (the deployed, managed resources)

Prerequisites: "What Is Infrastructure as Code?"

CloudFormation: AWS-native Infrastructure as Code

AWS CloudFormation is AWS's own Infrastructure as Code service. A CloudFormation template is a file — commonly written in YAML — that describes the AWS resources that should exist. Submitting a template to CloudFormation creates a stack: the deployed, managed collection of actual AWS resources described by that template.

Diagram showing a CloudFormation template submitted to CloudFormation, which creates a stack managing an S3 bucket, an SQS queue, and an IAM role, labeled with template as the definition and stack as the deployed collection of resources managed from it.
Template = definition. Stack = the deployed collection of resources managed from it — a distinction worth holding onto precisely.

A minimal, safe example template

Here is a deliberately minimal, fictional training example:

AWSTemplateFormatVersion: '2010-09-09'

Description: QuarryDev training example

Resources:
  TrainingBucket:
    Type: AWS::S3::Bucket

Reading this: AWSTemplateFormatVersion identifies the template-format syntax being used (this is a fixed value tied to CloudFormation's template format itself, not a claim about current AWS product versioning). Description is a human-readable label. Resources is where the actual infrastructure is defined — here, one fictional S3 bucket named TrainingBucket, of type AWS::S3::Bucket.

A brief note on reading the YAML itself: indentation indicates nesting (everything under Resources, indented further, belongs to it), and Key: Value pairs describe properties — that's enough YAML to follow every example in this module, without needing to learn YAML as its own subject.

Resources: the only section a template strictly needs

Diagram showing a template flowing conceptually from Parameters to Resources to Outputs, with Resources highlighted as the most important and only strictly required section, and a note that Mappings and Conditions can exist too but aren't needed for beginner templates.
Resources is the section that actually matters most — the next lesson goes deeper on Parameters and Outputs specifically.

A template can include other sections — Parameters and Outputs, covered in depth next lesson, and Mappings/Conditions for more advanced scenarios this module doesn't need — but Resources is the one section every useful template needs, since it's what actually defines the infrastructure.

Exercise

A colleague says "we already have a CloudFormation template, so our infrastructure is already deployed." Using this lesson's template-versus-stack distinction, explain what's imprecise about that statement, and what step actually has to happen for the infrastructure described by a template to exist as real AWS resources.

Show hint

A template describes what should exist — something still has to happen for that description to become a stack of real resources.

AWS CloudFormation Templates Quiz

1. What is the relationship between a CloudFormation template and a stack?

2. A CloudFormation template and a CloudFormation stack are the same thing.

3. AWS ______ is the AWS-native service used to define infrastructure using templates and deploy it as stacks.

Show hint

It's the service this entire lesson introduces.

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

AWS CloudFormation is AWS's native Infrastructure as Code service: a template — commonly written in YAML — defines the AWS resources that should exist, and submitting that template to CloudFormation creates a stack, a deployed and managed collection of the actual resources described by it; the template is the definition, and the stack is what results from deploying it.