Created
April 14, 2021 14:28
-
-
Save asolera/00c35d5ce81ae5ab374501d656012716 to your computer and use it in GitHub Desktop.
AWS CloudFormation Template for EC2 (AMI) with Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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