CloudFormation Basics

💤0
Lv 10 XP
← 🟧 Amazon Web Services · Infrastructure as Code

CloudFormation Basics

Intermediate ⭐ 80 XP ⏱ 18 min #aws#cloudformation#iac

Define and deploy AWS infrastructure as code with CloudFormation stacks.

📖Theory

CloudFormation is AWS’s native IaC service. You write a template (YAML or JSON) describing resources, and CloudFormation provisions them as a stack — a single managed unit you can update or delete together.

Template sections: Parameters (inputs), Resources (the actual infrastructure, required), Mappings/Conditions (logic), and Outputs (exported values). Change sets preview what an update will do before you apply it, and CloudFormation rolls back automatically if a deployment fails.

🌍Real-World Example
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  BucketName:
    Type: String
Resources:
  AppBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref BucketName
      VersioningConfiguration:
        Status: Enabled
Outputs:
  BucketArn:
    Value: !GetAtt AppBucket.Arn
aws cloudformation deploy --template-file s3.yaml \
  --stack-name my-bucket --parameter-overrides BucketName=my-unique-bucket
✍️Hands-On Exercise
  1. Identify the required section of a CloudFormation template.
  2. Add a parameter and reference it with !Ref.
  3. Explain what a change set is used for.
  4. Describe what happens to resources when you delete a stack.
🧾Cheat Sheet
SectionPurpose
ParametersInputs to the template
ResourcesInfrastructure (required)
Mappings/ConditionsLogic/lookups
OutputsExported values
StackDeployed unit of resources
Change setPreview an update
!Ref / !GetAttReference params/attributes
💬Common Interview Questions
What is a CloudFormation stack?

The collection of AWS resources created from a single template, managed as one unit — you create, update, or delete them together, with automatic rollback on failure.

What is a change set?

A preview of the changes a stack update would make before you execute it, so you can review additions, modifications, and deletions and avoid surprises.

📚Official Documentation

📝 My notes on this topic

Auto-saves as you type