Skip to main content

Command Palette

Search for a command to run...

Day 10: Stop Clicking, Start Coding — Introduction to AWS CloudFormation

Updated
2 min read
Day 10: Stop Clicking, Start Coding — Introduction to AWS CloudFormation
A
🚀 DevOps Engineer | Cloud Enthusiast | Automation Advocate I write about DevOps, Cloud Computing, and Infrastructure Automation, focusing on real-world projects using AWS, Ansible, Docker, Kubernetes, and CI/CD pipelines. My goal is to break down complex concepts into simple, practical, and beginner-friendly explanations that anyone can follow. I actively share hands-on tutorials, deployment strategies, troubleshooting guides, and lessons learned while working on cloud-native applications and automation workflows.

We’ve reached a massive milestone! For the past 9 days, we’ve been exploring the AWS Console. But in a professional DevOps environment, the Console is for viewing, not for building. Today, we enter the world of Infrastructure as Code (IaC) using AWS CloudFormation. We are going to stop being "Click-Ops" engineers and start being true DevOps Engineers.

1. What is Infrastructure as Code (IaC)?

IaC is the practice of managing and provisioning your tech stack through machine-readable definition files, rather than manual hardware configuration or interactive configuration tools.

Why CloudFormation?

  • Consistency: Deploy the exact same environment in Mumbai as you do in Virginia.

  • Version Control: You can commit your infrastructure to GitHub, track changes, and roll back if something breaks.

  • Speed: Build a complex VPC with subnets, RDS, and EC2 in minutes with a single command.

  • Cost Visibility: CloudFormation can estimate the cost of your stack before you even hit "Deploy."

2. The Anatomy of a CloudFormation Template

A template is a simple YAML or JSON file. It generally consists of these sections:

  • Parameters: Input values you provide at runtime (e.g., "What instance type do you want?").

  • Resources (Mandatory): The actual AWS components you want to create (e.g., an S3 bucket).

  • Mappings: Static variables (e.g., "If Region is us-east-1, use this AMI").

  • Outputs: Values you want to see after the stack is built (e.g., the URL of your new website).

3. Pro-Tips for IaC Mastery

  • The "Golden Rule" of Drift: Once you deploy a stack via CloudFormation, never change it manually in the Console. This causes "Drift," where your code no longer matches reality. Use Drift Detection to find and fix these gaps.

  • Intrinsic Functions: Learn !Ref (to reference another resource) and !GetAtt (to get a specific attribute, like an IP address). These are the "connective tissue" of your code.

  • Deletion Policies: For critical resources like RDS or S3, set DeletionPolicy: Retain. This ensures that even if the stack is deleted, the data stays safe.

  • Stack Sets: Use these if you need to deploy the same template across multiple AWS Accounts or Regions simultaneously.

🚀 Hands-on Challenge: Your First Template

Create a file named s3-bucket.yaml and paste this:

AWSTemplateFormatVersion: '2010-09-09'
Description: My first S3 Bucket via CloudFormation
Resources:
  MyDevOpsBucket:
    Type: 'AWS::S3::Bucket'
    Properties:
      BucketName: !Sub "devops-milestone-bucket-${AWS::AccountId}"
      VersioningConfiguration:
        Status: Enabled

More from this blog

A

AWS

28 posts