In this demo, we will:
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}'
WebAppStack
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