AWS CloudFormation
Hands-On
Demo

In this demo, we will:
- Create a CloudFormation template
- Launch a CloudFormation stack
- Update the stack
- Test the deployed resources
- Clean up resources
Agenda

Create CloudFormation Stack
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Simple web application infrastructure'
Parameters:
InstanceType:
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- t2.small
- t2.medium
Description: Enter t2.micro, t2.small, or t2.medium. Default is t2.micro.
Resources:
WebServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable HTTP access via port 80
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
WebServer:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0182f373e66f89c85 # Amazon Linux 2 AMI in us-east-1
InstanceType: !Ref InstanceType
SecurityGroups:
- !Ref WebServerSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from CloudFormation!</h1>" > /var/www/html/index.html
Outputs:
WebsiteURL:
Description: URL for the web server
Value: !Sub 'http://${WebServer.PublicDnsName}'

Create stack









WebAppStack
Specify stack details

Configure stack options


Stack failure options




Review and create







Submit

Event History



Resources

Outputs

Test
Update CloudFormation Stack

Update
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Simple web application infrastructure'
Parameters:
InstanceType:
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- t2.small
- t2.medium
Description: Enter t2.micro, t2.small, or t2.medium. Default is t2.micro.
Resources:
WebServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable HTTP access via port 80
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
WebServer:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0182f373e66f89c85 # Amazon Linux 2 AMI in us-east-1
InstanceType: !Ref InstanceType
SecurityGroups:
- !Ref WebServerSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from CloudFormation!</h1>" > /var/www/html/index.html
WebsiteBucket:
Type: AWS::S3::Bucket
Outputs:
WebsiteURL:
Description: URL for the web server
Value: !Sub 'http://${WebServer.PublicDnsName}'
S3BucketName:
Description: Name of the S3 bucket
Value: !Ref WebsiteBucket





Allows for Updating the EC2 Instance Type





Submit

Check Events

Resources

Outputs

Confirm S3 Bucket Creation
Clean Up

Delete CloudFormation Stack


Verify Event History

Verify S3 Bucket Deletion

Verify Security Group Deletion

Verify EC2 Instance Terminated
🙏
Thanks
for
Watching
AWS CloudFormation Hands-On Demo
By Deepak Dubey
AWS CloudFormation Hands-On Demo
AWS CloudFormation Hands-On Demo
- 198