CloudFormation Template Anatomy
What you'll learn: You'll understand the key sections that make up a CloudFormation template and how they work together to define your infrastructure.
A CloudFormation template is like a blueprint for your AWS infrastructure. Just as a building blueprint has distinct sections—foundation, framing, electrical—a CloudFormation template has well-defined sections that each serve a specific purpose.
Core Template Sections
Parameters: Think of these as customizable inputs when you create a stack. Instead of hardcoding values like instance sizes or environment names, parameters let you pass them in dynamically. This makes your templates reusable across different deployments.
Resources: This is the mandatory section—the heart of your template. Here you declare every AWS resource you want to create: EC2 instances, S3 buckets, VPCs, etc. Without resources, you have no infrastructure to build.
Outputs: After your stack is created, outputs expose useful information. You might output the URL of a load balancer, the ID of a created VPC, or the ARN of an S3 bucket. These values can be viewed in the console or referenced by other stacks.
How They Work Together
Imagine deploying a web server. Your Parameters section asks for the instance type. The Resources section creates the EC2 instance using that parameter. The Outputs section then displays the instance's public IP address so you know where to connect.
While templates can include additional sections (like Conditions or Mappings), these three form the foundation of most CloudFormation templates you'll write.
Key Takeaway: CloudFormation templates are structured documents where Parameters define inputs, Resources declare infrastructure components (required), and Outputs expose information—together forming a complete infrastructure definition.