-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0-cfn-hup-demo.yml
More file actions
79 lines (76 loc) · 2.56 KB
/
Copy path0-cfn-hup-demo.yml
File metadata and controls
79 lines (76 loc) · 2.56 KB
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
AWSTemplateFormatVersion: '2010-09-09'
Description: Deploy a web server with cfn-init and cfn-hup, serving a custom HTML page
Resources:
WebServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable HTTP access
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
MyInstance:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Init:
configSets:
default: ["install", "configure"]
install:
packages:
yum:
httpd: []
files:
"/etc/cfn/cfn-hup.conf":
content: !Sub |
[main]
stack=${AWS::StackId}
region=${AWS::Region}
interval=1
"/etc/cfn/hooks.d/cfn-auto-reloader.conf":
content: !Sub |
[cfn-auto-reloader-hook]
triggers=post.update
path=Resources.MyInstance.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource MyInstance --configsets default --region ${AWS::Region}
runas=root
configure:
files:
"/var/www/html/index.html":
content: |
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello, World! Welcome to my website!</h1>
<p> I've added some content to it </p>
</body>
</html>
mode: "000644"
owner: "root"
group: "root"
services:
sysvinit:
httpd:
enabled: "true"
ensureRunning: "true"
Properties:
ImageId: ami-0a3c3a20c09d6f377
InstanceType: "t3.micro"
SecurityGroups:
- Ref: WebServerSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y aws-cfn-bootstrap
# Initialize cfn-init
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource MyInstance --configsets default --region ${AWS::Region}
# Start cfn-hup
/opt/aws/bin/cfn-hup || error_exit 'Failed to start cfn-hup'
# Signal success
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource MyInstance --region ${AWS::Region}
Outputs:
WebsiteURL:
Description: URL of the website
Value: !Sub "http://${MyInstance.PublicDnsName}/"