Skip to main content
Welcome — in this lesson we walk through the essential building blocks of an AWS CloudFormation template and show how those sections fit together to define, configure, and output your infrastructure. A CloudFormation template is the single declarative artifact for provisioning AWS resources. It specifies the resources to create, accepts user inputs, enables conditional logic, and returns useful output values after stack creation. Core template sections are Resources, Parameters, and Outputs:
  • Resources — The only required section for most templates. Resources declare the AWS services to create (for example, AWS::EC2::Instance, AWS::S3::Bucket, or AWS::RDS::DBInstance).
  • Parameters — Optional user-supplied inputs passed to the template at stack creation time. Use parameters to avoid hard-coding values (for example: environment name, instance type, DB size).
  • Outputs — Optional values returned after stack creation, such as an instance public IP, a website URL, or other useful metadata.
A slide titled "CloudFormation – Template Components" showing three numbered blocks: Resources, Parameters, and Outputs, each with an icon and short explanation. It explains that resources define AWS services, parameters accept input values, and outputs return information like a website URL or public IP.
Below is a minimal YAML skeleton showing these sections and how they typically appear in a template. Use this as a starting point for small stacks or examples.
Use Parameters to make templates reusable across environments (dev, staging, prod). Favor references like !Ref and !Sub rather than hard-coded values to improve portability.
Core sections at a glance: Beyond the core sections, templates often include additional optional components to increase portability, validation, and conditional behavior:
  • Mappings — Static key/value tables used for lookups (for example, mapping regions to AMI IDs).
  • Conditions — Boolean expressions (using Fn::If, Fn::Equals, etc.) that control whether resources or properties are created based on parameters or other values.
  • Rules — Pre-deployment validations for parameters that catch incorrect input early.
These optional sections help make templates environment-aware and robust.
A slide titled "CloudFormation Template – Key Components" showing three optional blocks: 01 Mappings, 02 Conditions, and 03 Rules, each with an icon. The captions note that Mappings store static values, Conditions control resources based on parameters, and Rules validate parameter values before stack creation.
Common template metadata and helper features:
  • AWSTemplateFormatVersion — Optional document field (commonly "2010-09-09") that records the template format version.
  • Description — A human-readable summary of the template’s purpose.
  • Transform — Declares transforms (macros) applied to the template, for example AWS::Serverless-2016-10-31 for AWS SAM.
Avoid embedding secrets (passwords, API keys) directly in templates. Use AWS Secrets Manager, Systems Manager Parameter Store, or pass sensitive data securely at deployment time.
A presentation slide titled "CloudFormation Template – Key Components" showing three items: TemplateFormatVersion, Description, and Transform, each with an icon and brief explanatory text. The slide highlights these as key parts of an AWS CloudFormation template.
Template helpers — CloudFormation intrinsic functions — let you write dynamic, reusable templates:
  • Reuse parameter values with Ref (short form !Ref).
  • Retrieve resource attributes with Fn::GetAtt (short form !GetAtt).
  • Concatenate or format strings with Fn::Join or Fn::Sub.
  • Add conditional logic with Fn::If, Fn::Equals, etc.
Intrinsic functions are available in both short YAML tags (e.g., !Ref, !GetAtt) and long-form JSON equivalents (e.g., "Fn::GetAtt").
A presentation slide titled "Template Helper" explaining that intrinsic functions are used inside an AWS CloudFormation template to make it more dynamic and reusable. It shows a CloudFormation icon and four labeled buttons: Reuse parameter values, Get resource properties, Combine strings, and Add conditional logic.
Summary: Use Resources to define what you must create; Parameters and Mappings to make templates configurable; Conditions and Rules to control and validate behavior; and intrinsic functions to wire inputs, resources, and outputs together. For further reading:

Watch Video