Skip to main content
Welcome. This lesson covers AWS CloudFormation fundamentals from a practical Infrastructure-as-Code (IaC) perspective. CloudFormation lets you declare infrastructure as code (YAML or JSON templates) and deploy consistent, repeatable environments (stacks) across accounts and regions. Use templates to eliminate manual, non-repeatable processes and to ensure environments can be reproduced and versioned.
A diagram titled "Infrastructure as Code" showing an AWS blueprint containing AWS Lambda, Amazon S3, and Amazon EC2 icons. An arrow points to cloud resource icons and a "Code" box with a check mark, indicating deployment.
Summary: write the template once, store it in version control, and deploy it repeatedly by creating stacks (supply different parameters, stack names, or regions as needed). Core CloudFormation concepts
A slide titled "AWS CloudFormation Core Components" showing four icon cards labeled Template, Stack, Change Set, and Stack Sets. Each card uses a simple magenta/colored icon to represent a core CloudFormation concept.
High-level description: StackSets let you publish the same stack (for example, web-app + DB + network) across many regions/accounts in a coordinated way — think of StackSets as a way to apply a standardized template like a menu item across multiple environments. Templates (YAML / JSON) Templates declare AWS resources and the relationships between them. A CloudFormation template includes multiple top-level sections; some are required, others optional. The most commonly used sections are described in the table below. Templates most often combine Parameters, Resources, and Outputs. Transform is commonly used with the AWS Serverless Application Model (SAM).
A slide titled "CloudFormation Templates" showing a YAML template icon on the left with an arrow pointing to a box of AWS services on the right (AWS Lambda, Amazon S3, Amazon EC2). It illustrates deploying AWS resources from a CloudFormation YAML template.
Template anatomy diagram:
A diagram titled "CloudFormation Templates Section" showing a YAML template icon on the left. Blue rounded boxes list template sections such as AWSTemplateFormatVersion, Description, Parameters, Resources, Outputs, Conditions, Mappings, Metadata, and Transform.
Minimal valid template example This simple CloudFormation template creates a single EC2 instance and demonstrates four common sections: AWSTemplateFormatVersion, Description, Resources, and Outputs.
Notes:
  • Resources is required — a template without resources creates nothing.
  • Parameterize values such as InstanceType and ImageId for reuse across accounts/regions.
  • Store templates in Git to track changes and enable CI/CD pipelines.
Stacks A stack is a deployed CloudFormation template. In the AWS Console, a stack view includes tabs for Events, Resources, Outputs, Parameters, Change Sets, and the Template itself. The Resources tab lists created resources and their statuses.
The image shows an AWS CloudFormation Stack screen (Resources tab) listing one resource named SimpleEC2Instance with status CREATE_COMPLETE. A pink stack icon and the title "CloudFormation Stack" appear on the left.
Stack timeline CloudFormation exposes a timeline during stack creation and updates. Use the timeline to find which operations are in progress, succeeded, or failed and to troubleshoot delays or errors. When a stack operation fails, the console provides troubleshooting tools such as “View root cause.”
A screenshot of a "CloudFormation Stack Timeline" showing a deployment timeline for a resource named SimpleEC2Instance, with colored bars indicating phases (in progress, consistency check, complete). The left side shows a pink stack icon and the page includes timestamps across the timeline.
Change sets and drift detection
  • Change sets let you preview the impact of template updates before applying them. Use them to analyze resource replacements, property changes, or removals.
  • Drift detection compares the stack’s template-defined state with the actual live resources. It surfaces manual changes made outside CloudFormation.
After drift detection identifies differences, create a change set to decide whether to bring resources back in line or to accept manual changes. CloudFormation also provides lifecycle options such as rollback on failure and resource deletion policies to control behavior on errors or deletions.
A screenshot of an AWS CloudFormation "Execute change set?" dialog showing options for rollback behavior and deletion of newly created resources. The "Use deletion policy" option is selected and there's an orange "Execute change set" button at the bottom.
When updating stacks, always preview with change sets and enable rollback on failure unless you specifically need to inspect partial resources. Rolling back reduces the risk of leaving partially-created or inconsistent infrastructure.
How CloudFormation works (summary)
  1. Write the CloudFormation template (YAML/JSON).
  2. Deploy it to create a stack.
  3. Modify the stack through updates (using change sets) or detect and remediate drift.
  4. Monitor stack events, resources, and outputs; repeat as needed.
A slide titled "How AWS CloudFormation Works" showing a four-step flow: (01) Write the CloudFormation template, (02) Deploy the template as a stack, (03) Modify and update the stack, and (04) Monitor and detect drift. Each step is shown in a colored box connected by arrows.
CloudFormation in CI/CD CloudFormation integrates cleanly into CI/CD pipelines. A typical pipeline pattern is: Git repo (GitHub / GitLab / Bitbucket / CodeCommit) -> Build & test (e.g., CodeBuild) -> Synthesize (if using CDK) -> Deploy (CloudFormation). The AWS CDK generates CloudFormation templates from higher-level constructs and fits into the same pipeline, enabling code-first infrastructure that compiles down to CloudFormation templates.
Note: Many teams use external Git providers (GitHub, GitLab, Bitbucket) or AWS CodeCommit depending on organizational preference. Integrate your Git provider into CI/CD to automate template testing and CloudFormation deployments.
A diagram titled "Applying CloudFormation in CI/CD" showing an AWS CodePipeline flow: a developer pushes code to AWS CodeCommit, which goes to AWS CodeBuild and then to AWS CloudFormation. The CloudFormation step deploys resources into a VPC, with icons and arrows illustrating each pipeline stage.
Best practices
A presentation slide titled "AWS CloudFormation – Best Practices." It lists recommendations such as avoid hardcoding values, enable rollback on failure, use modular/nested templates, store templates in GitHub, automate deployments with AWS CodePipeline + CloudFormation, and avoid manual changes (configuration drift).
Final notes and references
  • For AWS-native provisioning, CloudFormation (and the CDK, which synthesizes to CloudFormation) is the primary native option.
  • Third-party tools (Terraform and its forks) are popular but outside of the AWS-native exam objectives.
Recommended reading and resources: For exam preparation, focus on:
  • Template sections and typical usage (Parameters, Resources, Outputs).
  • Stack behavior (creation, updates, rollback).
  • Change sets and drift detection.
  • Integrating templates into CI/CD pipelines.
That concludes this lesson on CloudFormation fundamentals. Practice by writing templates, creating stacks in a test account, using change sets, and automating deployments through CI/CD to build confidence and familiarity with CloudFormation operations.

Watch Video