</>
Skip to content
AWS lessons (39/47)

AWS — CloudFormation

What is CloudFormation?

Service for modeling and provisioning AWS resources.

Template structure

AWSTemplateFormatVersion: '2010-09-09'
Description: My CloudFormation Stack

Resources:
  MyBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-unique-bucket-name
      VersioningConfiguration:
        Status: Enabled

Create stack

aws cloudformation create-stack \
  --stack-name my-stack \
  --template-body file://template.yaml

Update stack

aws cloudformation update-stack \
  --stack-name my-stack \
  --template-body file://template.yaml

Delete stack

aws cloudformation delete-stack --stack-name my-stack

Parameters

Parameters:
  BucketName:
    Type: String
    Description: S3 bucket name

Resources:
  MyBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref BucketName

Outputs

Outputs:
  BucketArn:
    Value: !GetAtt MyBucket.Arn
    Export:
      Name: MyBucketArn

Stack sets

aws cloudformation create-stack-set \
  --stack-set-name my-stack-set \
  --template-body file://template.yaml

aws cloudformation create-stack-instances \
  --stack-set-name my-stack-set \
  --accounts [123456789012] \
  --regions [us-east-1,us-west-2]

Best practices

  1. Use version control
  2. Test changes first
  3. Use parameters for flexibility
  4. Set up drift detection

Mini Practice

  1. Create a simple template
  2. Deploy a stack
  3. Update the stack
  4. Use parameters

Up Next

Continue with API Gateway - API Management.

Related Topics

Frequently Asked Questions about CloudFormation

What is CloudFormation in AWS?

CloudFormation is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn CloudFormation?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn CloudFormation.

Why is CloudFormation important in AWS?

CloudFormation is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.