-
Notifications
You must be signed in to change notification settings - Fork 1
/
2_cfn-hup.yml
97 lines (97 loc) · 2.9 KB
/
2_cfn-hup.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
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
91
92
93
94
95
96
97
AWSTemplateFormatVersion: "2010-09-09"
Description: Cfn Helper Script Sample
Parameters:
VpcId:
Type: 'AWS::EC2::VPC::Id'
Description: Your default VPC Id
SubnetId:
Type: 'AWS::EC2::Subnet::Id'
Description: SubnetId in your default VPC
KeyName:
Type: 'AWS::EC2::KeyPair::KeyName'
Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
FromIpAddress:
Type: String
Description: The IP address range that can be used to SSH and HTTP to the EC2 instances
Default: 0.0.0.0/0
AmiId:
Description: AMI Id
Type: String
Default: ami-0a1c2ec61571737db
Resources:
ServerInstance:
Type: AWS::EC2::Instance
Metadata:
Comment: Install a simple web app
AWS::CloudFormation::Init:
config:
packages:
yum:
httpd: []
files:
/var/www/html/index.html:
content: !Sub |
<p>Hello!</p>
mode: '000644'
owner: root
group: root
/etc/cfn/cfn-hup.conf:
content: !Sub |
[main]
stack=${AWS::StackName}
region=${AWS::Region}
interval=1
mode: '000400'
owner: root
group: root
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: !Sub |
[cfn-auto-reloader-hook]
triggers=post.update
path=Resources.ServerInstance.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init -v \
--stack ${AWS::StackName} \
--resource ServerInstance \
--region ${AWS::Region}
runas=root
services:
sysvinit:
httpd:
enabled: 'true'
ensureRunning: 'true'
cfn-hup:
enabled: 'true'
ensureRunning: 'true'
files:
- /etc/cfn/cfn-hup.conf
- /etc/cfn/hooks.d/cfn-auto-reloader.conf
Properties:
ImageId: !Ref AmiId
InstanceType: t3.micro
SecurityGroupIds:
- !Ref InstanceSecurityGroup
KeyName: !Ref KeyName
SubnetId : !Ref SubnetId
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
/opt/aws/bin/cfn-init -v \
--stack ${AWS::StackName} \
--resource ServerInstance \
--region ${AWS::Region}
InstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable SSH access and HTTP access on the inbound port
SecurityGroupIngress:
-
IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref FromIpAddress
-
IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: !Ref FromIpAddress
VpcId: !Ref VpcId