-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathec2-stack.yaml
90 lines (77 loc) · 2.25 KB
/
ec2-stack.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
Parameters:
AvailabilityZone:
Type: String
Default: us-east-1a
AmazonLinux2AMI:
Type: String
Default: ami-0b5eea76982371e91
Resources:
DockerComposeInstance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: !Ref AvailabilityZone
ImageId: !Ref AmazonLinux2AMI
InstanceType: t2.micro
UserData:
Fn::Base64:
|
#!/bin/bash
yum update -y
# Install Docker
amazon-linux-extras install docker -y
service docker start
systemctl enable docker
usermod -a -G docker ec2-user
chmod 666 /var/run/docker.sock
# Install Docker Compose
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# Mount Drive
mkdir /data
mkfs -t xfs /dev/xvdh
mount /dev/xvdh /data
# Install git in your EC2 instance
yum install git -y
# Clone and run a sample application
cd ~
git clone https://github.com/kobbikobb/guessthename.git
cd guessthename
docker-compose --file docker-compose-explicit.yaml up
SecurityGroups:
- !Ref SSHSecurityGroup
- !Ref HTTPSecurityGroup
SSHSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 22
ToPort: 22
IpProtocol: tcp
HTTPSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: Enable standard web access
SecurityGroupIngress:
- CidrIp: "0.0.0.0/0"
FromPort: 80
ToPort: 80
IpProtocol: tcp
ExternalVolume:
Type: AWS::EC2::Volume
Properties:
AvailabilityZone: !Ref AvailabilityZone
Size: 4
VolumeType: gp2
MountPoint:
Type: AWS::EC2::VolumeAttachment
Properties:
InstanceId: !Ref DockerComposeInstance
VolumeId: !Ref ExternalVolume
Device: /dev/xvdh
ElasticIp:
Type: AWS::EC2::EIP
Properties:
InstanceId: !Ref DockerComposeInstance