Skip to content

Instantly share code, notes, and snippets.

@sshplendid
Last active November 18, 2019 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sshplendid/f0de7a8264c2b8883425dbfbb37e9d03 to your computer and use it in GitHub Desktop.
Save sshplendid/f0de7a8264c2b8883425dbfbb37e9d03 to your computer and use it in GitHub Desktop.
CloudFormation template for single EC2 web server
AWSTemplateFormatVersion: 2010-09-09
Metadata:
MyMeta:
apple: red
bannna: yellow
Parameters:
owner:
Description: This stack owner's name
Type: String
Default: 'Shawn'
Resources:
MyEC2SecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupName: MyWebSecurity
GroupDescription: 'This is my web server security group'
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
CidrIp: 0.0.0.0/0
ToPort: 22
Tags:
- Key: Name
Value: MySG
- Key: CreatedBy
Value: CloudFormation
WebServerIngress:
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
CidrIp: 0.0.0.0/0
Description: WebServerIngress By CloudFormation
FromPort: 80
GroupName: !Ref MyEC2SecurityGroup
IpProtocol: tcp
ToPort: 80
MyWebServer:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: ami-02b3330196502d247
InstanceType: t2.micro
SecurityGroups:
- !Ref MyEC2SecurityGroup
Tags:
- Key: Name
Value: !Sub
- 'WebServerBy ${param}'
- { param: !Ref owner }
UserData:
Fn::Base64:
!Sub |
#!/bin/bash
yum update -y
yum install -y httpd.x86_64
systemctl start httpd.service
systemctl enable httpd.service
echo "Hello Cloud Formation from $(hostname -f)... at $(date)" > /var/www/html/index.html
Outputs:
MyStackRegion:
Description: This is the output description.
Value: !Ref 'AWS::Region'
StackOwner:
Description: This stack creator
Value: !Ref owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment