-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathsc-ec2-linux-nginx-nokey.json
151 lines (151 loc) · 4.99 KB
/
sc-ec2-linux-nginx-nokey.json
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
{
"Description": "AWS EC2 NGINX webserver (fdp-1p4dlgcpk)",
"Parameters": {
"VPC": {
"Type": "AWS::EC2::VPC::Id",
"Description": "Select the VPC where the EC2 instances will be created",
"ConstraintDescription": "must be an existing VPC"
},
"InstanceType": {
"Type": "String",
"Default":"t3.micro",
"AllowedValues": ["t2.micro","t2.medium","t3.micro","t3.medium","t3.large"]
},
"LatestAmiId": {
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
"Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
}
},
"Resources": {
"WebSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable HTTP and HTTPS access",
"VpcId" : {"Ref" : "VPC"},
"SecurityGroupIngress" : [
{"Description":"allow incoming HTTP", "IpProtocol" : "tcp", "FromPort" : 80, "ToPort" : 80, "CidrIp" : "0.0.0.0/0" },
{"Description":"allow incoming HTTPS", "IpProtocol" : "tcp", "FromPort" : 443, "ToPort" : 443, "CidrIp" : "0.0.0.0/0" },
{"Description":"allow icmp", "IpProtocol": "icmp","FromPort": "-1","ToPort": "-1", "CidrIp": "0.0.0.0/0" },
{"Description":"allow SSH", "IpProtocol": "tcp","FromPort": "22","ToPort": "22", "CidrIp": "0.0.0.0/0" }
],
"SecurityGroupEgress" : [
{"Description":"allow outgoing HTTP", "IpProtocol" : "tcp", "FromPort" : 80, "ToPort" : 80, "CidrIp" : "0.0.0.0/0" },
{"Description":"allow outgoing HTTPS", "IpProtocol" : "tcp", "FromPort" : 443, "ToPort" : 443, "CidrIp" : "0.0.0.0/0" }
]
}
},
"WebServerInstance": {
"Type": "AWS::EC2::Instance",
"Metadata": {
"AWS::CloudFormation::Init": {
"configSets": {
"All": [
"extras",
"confignginx"
]
},
"extras":{
"commands": {
"enable_nginx": {
"command":"amazon-linux-extras enable nginx1.12"
}
}
},
"confignginx": {
"packages": {
"yum": {
"nginx": []
}
},
"files": {
"/usr/share/nginx/html/index.html": {
"content": {
"Fn::Join": [
"\n",
[
"<h1>Welcome to your new NGINX webserver. web files can be found in /usr/share/nginx/html </h1>"
]
]
},
"mode": "000644",
"owner": "root",
"group": "root"
}
},
"services": {
"sysvinit": {
"nginx": {
"enabled": "true",
"ensureRunning": "true"
}
}
}
}
}
},
"Properties": {
"InstanceType": {
"Ref": "InstanceType"
},
"ImageId": {
"Ref":"LatestAmiId"
},
"Tags" : [
{"Key" : "Name", "Value" : {"Fn::Sub":"EC2-NGINX-${AWS::StackName}"} }
],
"SecurityGroupIds" :[{ "Fn::GetAtt": ["WebSecurityGroup", "GroupId"] }],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash -xe\n",
"yum update -y aws-cfn-bootstrap\n",
"# Install the files and packages from the metadata\n",
"/opt/aws/bin/cfn-init -v ",
" --stack ",
{
"Ref": "AWS::StackName"
},
" --resource WebServerInstance ",
" --configsets All ",
" --region ",
{
"Ref": "AWS::Region"
},
"\n",
"# Signal the status from cfn-init\n",
"/opt/aws/bin/cfn-signal -e $? ",
" --stack ",
{
"Ref": "AWS::StackName"
},
" --resource WebServerInstance ",
" --region ",
{
"Ref": "AWS::Region"
},
"\n"
]
]
}
}
},
"CreationPolicy": {
"ResourceSignal": {
"Timeout": "PT5M"
}
}
}
},
"Outputs": {
"WebsiteURL": {
"Description": "DNS root URL of the new webserver",
"Value" : { "Fn::Join" : [ "", ["http://", { "Fn::GetAtt" : ["WebServerInstance", "PublicDnsName"] }]]}
},
"WebsiteIP": {
"Description": "IP root URL of the new webserver",
"Value" : { "Fn::Join" : [ "", ["http://", { "Fn::GetAtt" : ["WebServerInstance", "PublicIp"] }]]}
}
}
}