-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcfn-template.yml
57 lines (52 loc) · 1.71 KB
/
cfn-template.yml
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
AWSTemplateFormatVersion: 2010-09-09
Description: >
This CloudFormation Template creates a Docker engine on EC2 Instance for React Marvel API. Docker Machine will run on Amazon Linux 2 EC2 Instance with
custom security group allowing SSH connections from anywhere on port 22.
Parameters:
KeyPairName:
Description: Enter the name of your Key Pair for SSH connections.
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: Must one of the existing EC2 KeyPair
Default: "virginia"
Resources:
DockerMachineSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH for Docker Machine
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
DockerMachine:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-09d95fab7fff3776c
InstanceType: t2.micro
KeyName: !Ref KeyPairName
SecurityGroupIds:
- !GetAtt DockerMachineSecurityGroup.GroupId
Tags:
- Key: Name
Value: !Sub Docker Machine of ${AWS::StackName}
UserData:
Fn::Base64: |
#! /bin/bash
yum update -y
amazon-linux-extras install docker -y
systemctl start docker
systemctl enable docker
usermod -a -G docker ec2-user
newgrp docker
docker pull devenes/marvel-api:2
docker run -d -p 80:3000 --name marvel-api devenes/marvel-api:2
Outputs:
WebsiteURL:
Description: Docker Machine DNS Name
Value: !Sub
- ${PublicAddress}
- PublicAddress: !GetAtt DockerMachine.PublicDnsName