-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2lamp.yaml
231 lines (220 loc) · 5.88 KB
/
ec2lamp.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
AWSTemplateFormatVersion: 2010-09-09
Description: >-
AWS CloudFormation LAMP Template
Metadata:
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: Database settings
Parameters:
- DBName
- DBUser
- DBPassword
- DBRootPassword
- Label:
default: Settings
Parameters:
- SymfonyInstallation
- PhpMyAdminInstallation
- JenkinsInstallation
- Label:
default: VPC Info
Parameters:
- VpcId
- SubnetId
Parameters:
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
Type: 'AWS::EC2::KeyPair::KeyName'
ConstraintDescription: must be the name of an existing EC2 KeyPair.
DBName:
Default: MyDatabase
Description: MySQL database name
Type: String
MinLength: '1'
MaxLength: '64'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
DBUser:
Description: Username for MySQL database access
Type: String
MinLength: '1'
MaxLength: '16'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
DBPassword:
NoEcho: 'true'
Description: Password for MySQL database access
Type: String
MinLength: '1'
MaxLength: '41'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: must contain only alphanumeric characters.
DBRootPassword:
NoEcho: 'true'
Description: Root password for MySQL
Type: String
MinLength: '1'
MaxLength: '41'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: must contain only alphanumeric characters.
SSHLocation:
Description: ' The IP address range that can be used to SSH to the EC2 instances'
Type: String
MinLength: '9'
MaxLength: '18'
Default: 0.0.0.0/0
AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
SymfonyInstallation:
Default: true
Description: Do you want to install a symfony project?
Type: String
AllowedValues:
- true
- false
ConstraintDescription: must be either true or false.
PhpMyAdminInstallation:
Default: true
Description: Do you want to install phpMyAdmin?
Type: String
AllowedValues:
- true
- false
ConstraintDescription: must be either true or false'
JenkinsInstallation:
Default: false
Description: Do you want to install jenkins?
Type: String
AllowedValues:
- true
- false
ConstraintDescription: must be either true or false.
VpcId:
Description: The VPC ID
Type: 'AWS::EC2::VPC::Id'
SubnetId:
Description: The Subnet ID
Type: 'AWS::EC2::Subnet::Id'
InstanceType:
Description: WebServer EC2 instance type
Type: String
Default: t2.nano
AllowedValues:
- t1.micro
- t2.nano
- t2.micro
- t2.small
- t2.medium
- t2.large
- m1.small
- m1.medium
- m1.large
- m1.xlarge
- m2.xlarge
- m2.2xlarge
- m2.4xlarge
- m3.medium
- m3.large
- m3.xlarge
- m3.2xlarge
- m4.large
- m4.xlarge
- m4.2xlarge
- m4.4xlarge
- m4.10xlarge
- c1.medium
- c1.xlarge
- c3.large
- c3.xlarge
- c3.2xlarge
- c3.4xlarge
- c3.8xlarge
- c4.large
- c4.xlarge
- c4.2xlarge
- c4.4xlarge
- c4.8xlarge
- g2.2xlarge
- g2.8xlarge
- r3.large
- r3.xlarge
- r3.2xlarge
- r3.4xlarge
- r3.8xlarge
- i2.xlarge
- i2.2xlarge
- i2.4xlarge
- i2.8xlarge
- d2.xlarge
- d2.2xlarge
- d2.4xlarge
- d2.8xlarge
- hi1.4xlarge
- hs1.8xlarge
- cr1.8xlarge
- cc2.8xlarge
- cg1.4xlarge
ConstraintDescription: must be a valid EC2 instance type.
AmiID:
Description: The ID of the AMI.
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
Default: >-
/aws/service/canonical/ubuntu/server/focal/stable/current/amd64/hvm/ebs-gp2/ami-id
Resources:
WebServerSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable HTTP access via port 80 and 8080 for example for jenkins
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '8080'
ToPort: '8080'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref SSHLocation
VpcId: !Ref VpcId
WebServerInstance:
Type: 'AWS::EC2::Instance'
Properties:
SubnetId: !Ref SubnetId
ImageId: !Ref AmiID
InstanceType: !Ref InstanceType
SecurityGroupIds:
- !GetAtt WebServerSecurityGroup.GroupId
Tags:
- Key: Name
Value: Ubuntu20 Web + SSH Server
KeyName: !Ref KeyName
UserData:
'Fn::Base64': !Sub >
#!/bin/bash
sudo curl
https://raw.githubusercontent.com/SynergygraphicIB/CloudFormation-Ubuntu-Lamp/main/lamp
-o /lamp
# GitHub data have to be at the end and use Token
sudo chmod +x /lamp
/./lamp ${AWS::StackName} ${DBUser} ${DBPassword} ${DBName}
${DBRootPassword} ${SymfonyInstallation} ${PhpMyAdminInstallation}
${JenkinsInstallation}
rm -r /lamp
WebServerEIP:
Type: 'AWS::EC2::EIP'
Properties:
Domain: vpc
InstanceId: !Ref WebServerInstance
Outputs:
WebsiteURL:
Description: URL for newly created LAMP stack
Value: !Join
- ''
- - 'http://'
- !GetAtt
- WebServerInstance
- PublicDnsName