Study guide
Technical reference and lesson notes
AWS CloudFormation: Templates, Stacks, StackSets, and Change Sets
Purpose of This Lesson
AWS CloudFormation lets you define AWS infrastructure as code in JSON or YAML templates. CloudFormation uses those templates to make the required AWS API calls and provision, update, or delete the defined resources.
For the AWS Certified CloudOps Engineer Associate SOA-C03 context, focus on recognizing which CloudFormation component or workflow is appropriate: a template describes the desired infrastructure, a stack represents a deployed unit, a StackSet coordinates stacks across accounts and Regions, and a change set previews modifications before they are applied.
Key Concepts
CloudFormation template
A template is a text file written in JSON or YAML that describes what CloudFormation should build. A template can define infrastructure such as:
- VPCs and CIDR blocks
- Public and private subnets
- Resources distributed across multiple Availability Zones
- Auto Scaling groups
- Amazon EC2 instances
- Application Load Balancers
The template is the reusable set of instructions. Correctly defining it once allows the same infrastructure design to be deployed repeatedly with less manual effort and fewer human errors.
Stack
A stack is the managed AWS environment created from a CloudFormation template. The resources created from that template are treated as a unit that CloudFormation can create, update, and delete.
A stack therefore provides an operational boundary for a related collection of resources. Deleting the stack can cause CloudFormation to make the necessary API calls to remove the resources defined by that stack.
StackSet
A StackSet extends the stack model across multiple AWS accounts and Regions. It allows stacks to be created, updated, and deleted centrally across those accounts and Regions through one operation rather than requiring separate stack management in each location.
Change set
A change set is used to review a proposed modification to an existing stack. You provide an updated template, and CloudFormation shows the changes that would be made before those changes are implemented.
Change sets are especially useful when the impact of an update needs to be assessed before affecting production resources. Creating or reviewing a change set is not the same as applying the update.
Infrastructure Provisioning with CloudFormation
The basic workflow is:
- Define the desired AWS resources and configuration in a JSON or YAML template.
- Supply the template to CloudFormation.
- CloudFormation makes the relevant AWS API calls to create the resources.
- Manage the resulting environment as a stack.
- Use an updated template and, when appropriate, a change set to evaluate and apply modifications.
- Delete the stack when the complete managed environment is no longer required.
A single template can describe a relatively complex environment. For example, a design might include a VPC, public and private subnets across multiple Availability Zones, an Auto Scaling group, EC2 instances, and an Application Load Balancer.
Benefits and Operational Tradeoffs
Consistency and reduced human error
Manual provisioning requires repeating configuration steps and increases the chance of inconsistent settings or omissions. A validated template provides a repeatable definition that can be reused across deployments.
Speed and reduced effort
CloudFormation can provision complex infrastructure in minutes compared with the potentially much longer process of configuring each resource manually.
Version control and peer review
Templates are code-like artifacts. Teams can store them in version control, review proposed changes, and retain a history of how the infrastructure definition evolved.
Dependency and lifecycle management
CloudFormation manages the resources described by a stack and can handle updates and dependencies as part of stack operations. It also supports deleting the stack as a unit rather than requiring every resource to be removed manually.
Cost consideration
CloudFormation itself is free to use according to the lesson. The AWS resources provisioned through CloudFormation still incur their normal charges. Free CloudFormation usage does not make the deployed VPC, EC2 instances, load balancer, or other resources free.
Exam- or Assessment-Relevant Takeaways
- A template is the JSON or YAML definition of the desired AWS infrastructure.
- A stack is the deployed and managed collection of resources created from a template.
- A StackSet manages stacks across multiple AWS accounts and Regions from a central operation.
- A change set previews how an updated template would modify an existing stack before implementation.
- CloudFormation is infrastructure as code: it automates the AWS API calls needed to build the declared environment.
- Reusable templates improve consistency, support version control and peer review, and reduce manual configuration effort.
- Deleting a stack is a lifecycle operation that can remove the resources managed by that stack.
- CloudFormation does not eliminate charges for the AWS resources it provisions.
Tool / Feature Decision Guide
| Requirement | Appropriate CloudFormation capability | Reason |
|---|---|---|
| Define a VPC, subnets, compute, and load-balancing resources as code | Template | The template contains the desired infrastructure definition. |
| Deploy and manage the resources described by one template as a unit | Stack | A stack is the managed environment created from the template. |
| Deploy equivalent stacks across multiple accounts and Regions | StackSet | StackSets centrally create, update, and delete stacks across those scopes. |
| Inspect the effect of an updated template before applying it | Change set | A change set previews proposed stack modifications. |
| Repeatedly provision the same architecture with fewer manual differences | Reusable template and stack workflow | The infrastructure definition can be reused instead of rebuilt manually. |
Common Traps / Misconceptions
- Confusing a template with a stack: The template is the file containing instructions; the stack is the deployed environment managed from those instructions.
- Confusing StackSets with a normal stack: A normal stack manages one deployed environment, while a StackSet coordinates stacks across multiple accounts and Regions.
- Assuming a change set automatically performs the update: A change set shows the proposed impact. The update still needs to be implemented.
- Assuming CloudFormation is completely cost-free: The CloudFormation capability is free, but the resources it provisions are billed normally.
- Thinking manual resource deletion is always required: CloudFormation can delete the resources managed by a stack when the stack is deleted.
- Treating templates as disposable console settings: Templates should be maintained as reusable, reviewable, version-controlled infrastructure definitions.
- Overlooking the scope of a stack: Resources created from a template are managed together, so stack lifecycle actions can affect the entire defined environment.
Real-World Engineer / Analyst Notes
- Use templates to make infrastructure changes repeatable and reviewable rather than relying on undocumented console actions.
- Peer review is valuable because a template can create or remove multiple related resources through one stack operation.
- Before changing an existing environment, use a change set when you need to understand the proposed impact, particularly for production-oriented workflows.
- Treat stack deletion as a consequential lifecycle action. Confirm which resources belong to the stack and whether removing the environment is intended.
- When the same infrastructure pattern must exist in multiple accounts or Regions, evaluate StackSets instead of manually creating independent stacks.
- Remember that CloudFormation automates provisioning; it does not remove the operational or financial responsibility associated with the resources being provisioned.
Quick Reference Summary
| Term | Meaning |
|---|---|
| Template | JSON or YAML file describing the AWS resources and configuration to build. |
| Stack | Managed environment created from a template; resources are handled as a unit. |
| StackSet | Centralized management of stacks across multiple accounts and Regions. |
| Change set | Preview of proposed changes to an existing stack before implementation. |
| Main value | Consistent, repeatable, reviewable infrastructure provisioning with less manual effort. |
| Cost rule | CloudFormation is free to use, but provisioned AWS resources incur their normal charges. |
Flashcards
Q: A team needs to define a VPC, subnets, EC2 instances, and an Application Load Balancer in a reusable file. Which CloudFormation object should contain this definition?
A: A CloudFormation template written in JSON or YAML. The template is the infrastructure-as-code definition supplied to CloudFormation.
Q: What is the decisive difference between a CloudFormation template and a stack?
A: A template is the set of instructions, while a stack is the deployed environment and managed collection of resources created from those instructions.
Q: When should a team choose a StackSet instead of managing a single stack?
A: Use a StackSet when equivalent stacks must be created, updated, or deleted across multiple AWS accounts and Regions through centralized operations.
Q: An engineer has prepared an updated template but wants to inspect its effect before changing an existing production stack. Which feature should be used?
A: Use a change set. It previews the proposed stack changes before they are implemented.
Q: Does creating a change set itself apply the proposed infrastructure update?
A: No. A change set provides a preview; the proposed update must still be implemented separately.
Q: Why does CloudFormation generally reduce provisioning mistakes compared with manual configuration?
A: The desired configuration is defined once in a reusable template, reducing repeated human entry and inconsistencies across deployments.
Q: What happens conceptually when CloudFormation receives a valid infrastructure template?
A: CloudFormation makes the relevant AWS API calls to create the resources described by the template and manages them as a stack.
Q: A company wants an auditable history of infrastructure-definition changes and team review before deployment. What CloudFormation practice supports this?
A: Store templates in version control and use peer review. Templates are code-like artifacts whose revisions can be tracked and reviewed.
Q: How do a normal stack and a StackSet differ in deployment scope?
A: A normal stack represents one deployed environment, whereas a StackSet centrally manages stacks across multiple accounts and Regions.
Q: What is the operational significance of deleting a CloudFormation stack?
A: CloudFormation can make the API calls needed to terminate and delete the resources managed by that stack, returning the environment toward its pre-deployment state.
Q: A learner says, “CloudFormation deployments are free, so the EC2 instances and load balancer cost nothing.” What is wrong with this statement?
A: CloudFormation itself is free to use, but AWS resources provisioned through it still incur their normal charges.
Q: Why is a stack useful as a management boundary?
A: The related resources created from a template can be created, updated, and deleted as a unit rather than being managed independently.
Practice Questions
Question 1
A platform team must deploy the same VPC and application infrastructure into several AWS accounts and Regions. The team wants one centrally managed operation rather than creating each deployment independently. What should it use?
A. A separate template file for every account and Region
B. A change set for one existing stack
C. A StackSet
D. A single stack in one Region
Correct answer: C. A StackSet. StackSets are designed to create, update, and delete stacks across multiple accounts and Regions through centralized management.
Question 2
An updated CloudFormation template is ready, but the operations team needs to understand the proposed impact before modifying an existing production environment. What is the best next step?
A. Delete the existing stack and recreate it
B. Create a change set from the updated template
C. Convert the stack into a StackSet
D. Manually change each resource in the AWS console
Correct answer: B. Create a change set from the updated template. The decisive clue is the requirement to preview the proposed changes before implementation.
Question 3
A company manually provisions a multi-AZ VPC with public and private subnets, an Auto Scaling group, EC2 instances, and an Application Load Balancer. The same architecture must be recreated consistently. Which approach best addresses the requirement?
A. Define the environment in a reusable CloudFormation template
B. Create a change set without an existing stack
C. Use a StackSet only if there is one account and one Region
D. Repeat the console procedure and document it afterward
Correct answer: A. Define the environment in a reusable CloudFormation template. A template captures the infrastructure definition for repeatable provisioning with less manual effort and fewer configuration mistakes.
Question 4
An engineer wants to remove an entire environment that was provisioned and managed by CloudFormation. Which action most directly matches this lifecycle goal?
A. Delete the stack
B. Create a new change set
C. Edit the template in version control only
D. Create a second StackSet in the same account
Correct answer: A. Delete the stack. Stack deletion tells CloudFormation to remove the resources managed by that stack through the relevant AWS API calls.
Question 5
A project lead claims that using CloudFormation eliminates all infrastructure costs because CloudFormation is free. Which response is accurate?
A. CloudFormation charges only when StackSets are used
B. CloudFormation is free, and all resources created by it are also free
C. CloudFormation is free to use, but the provisioned AWS resources are billed normally
D. CloudFormation charges a fixed percentage of each resource’s cost
Correct answer: C. The lesson distinguishes the free CloudFormation capability from the normal charges for resources it provisions.
WordPress Metadata
Suggested Slug:
aws-cloudformation-templates-stacks-stacksets-change-sets
Meta Description:
Study AWS CloudFormation fundamentals, including template-driven provisioning, stacks, StackSets, change sets, benefits, and deployment decision points for the CloudOps Engineer Associate exam.
Tags:
AWS CloudFormation, AWS Certified CloudOps Engineer, infrastructure as code, CloudFormation templates, CloudFormation stacks, StackSets, change sets, AWS automation, AWS deployment, AWS resource management