Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS CloudFormation Template for EC2 (AMI) with Docker
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation Template for EC2 (AMI) with Docker
Parameters:
EC2AvailabilityZoneParam:
Type: String
Default: us-east-1a
EC2ImageNameParam:
Type: String
Default: ami-0533f2ba8a1995cf9
EC2InstanceTypeParam:
Type: String
Default: t3a.micro
EC2KeyNameParam:
Type: String
EBSVolumeSizeParam:
Type: Number
Default: 20
Resources:
EC2Server:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: !Ref EC2AvailabilityZoneParam
BlockDeviceMappings:
-
DeviceName: "/dev/xvda"
Ebs:
DeleteOnTermination: 'false'
Iops: 3000
VolumeSize: !Ref EBSVolumeSizeParam
VolumeType: 'gp3'
DisableApiTermination: true
ImageId: !Ref EC2ImageNameParam
InstanceType: !Ref EC2InstanceTypeParam
KeyName: !Ref EC2KeyNameParam
Monitoring: true
SecurityGroups:
- !Ref SSHSecurityGroup
- !Ref WebSecurityGroup
UserData:
Fn::Base64:
Fn::Sub:
- |
sudo yum update -y
sudo amazon-linux-extras install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo chkconfig docker on
sudo yum install -y git
sudo reboot
EIP:
Type: AWS::EC2::EIP
Properties:
InstanceId: !Ref EC2Server
SSHSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SSH access
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 22
IpProtocol: tcp
ToPort: 22
WebSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: HTTP-HTTPS access
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: tcp
ToPort: 80
- CidrIp: 0.0.0.0/0
FromPort: 443
IpProtocol: tcp
ToPort: 443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment