-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
85 lines (75 loc) · 2.38 KB
/
template.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
Parameters:
nameOfService:
Description: "The name of the instance"
Type: String
InstanceType:
Description: "The instance type"
Default: t2.micro
AllowedValues:
- t2.micro
- t2.small
- t2.medium
Type: String
KeyPair:
Description: "The key pair"
Type: AWS::EC2::KeyPair::KeyName
Resources:
CoffeeShopInstance:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Init:
config:
packages:
apt:
apache2: []
unzip: []
services:
sysvinit:
apache2:
enabled: true
ensureRunning: true
commands:
test:
command: "wget https://www.tooplate.com/zip-templates/2126_antique_cafe.zip && unzip 2126_antique_cafe.zip && cp -r 2126_antique_cafe/* /var/www/html/"
Properties:
ImageId: ami-04ff9e9b51c1f62ca
InstanceType: !Ref InstanceType
KeyName: !Ref KeyPair
Tags:
- Key: Name
Value: !Ref nameOfService
SecurityGroups:
- !Ref MySecurityGroup
UserData:
"Fn::Base64":
!Sub |
#!bin/bash
sudo apt update -y
mkdir -p /opt/aws/bin
wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource CoffeeShopInstance --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource CoffeeShopInstance --region ${AWS::Region}
CreationPolicy:
ResourceSignal:
Count: 1
Timeout: PT5M
MySecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Join [" ", ["My security group from", !Ref "AWS::StackName"]]
GroupDescription: !Join [" ", ["My security group from", !Ref "AWS::StackName"]]
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
Outputs:
PublicIp:
Value: !GetAtt [CoffeeShopInstance, PublicIp]
PublicDnsName:
Value: !GetAtt [CoffeeShopInstance, PublicDnsName]