Last active 1559094937

generated by AWS cloudformation

aws-cloudformation-lamp-test.yml Raw
1AWSTemplateFormatVersion: 2010-09-09
2Description: >-
3 AWS CloudFormation Sample Template LAMP_Single_Instance: Create a LAMP stack
4 using a single EC2 instance and a local MySQL database for storage. This
5 template demonstrates using the AWS CloudFormation bootstrap scripts to
6 install the packages and files necessary to deploy the Apache web server, PHP
7 and MySQL at instance launch time. **WARNING** This template creates an Amazon
8 EC2 instance. You will be billed for the AWS resources used if you create a
9 stack from this template.
10Parameters:
11 KeyName:
12 Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
13 Type: 'AWS::EC2::KeyPair::KeyName'
14 ConstraintDescription: must be the name of an existing EC2 KeyPair.
15 DBName:
16 Default: MyDatabase
17 Description: MySQL database name
18 Type: String
19 MinLength: '1'
20 MaxLength: '64'
21 AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
22 ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
23 DBUser:
24 NoEcho: 'true'
25 Description: Username for MySQL database access
26 Type: String
27 MinLength: '1'
28 MaxLength: '16'
29 AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
30 ConstraintDescription: must begin with a letter and contain only alphanumeric characters.
31 DBPassword:
32 NoEcho: 'true'
33 Description: Password for MySQL database access
34 Type: String
35 MinLength: '1'
36 MaxLength: '41'
37 AllowedPattern: '[a-zA-Z0-9]*'
38 ConstraintDescription: must contain only alphanumeric characters.
39 DBRootPassword:
40 NoEcho: 'true'
41 Description: Root password for MySQL
42 Type: String
43 MinLength: '1'
44 MaxLength: '41'
45 AllowedPattern: '[a-zA-Z0-9]*'
46 ConstraintDescription: must contain only alphanumeric characters.
47 InstanceType:
48 Description: WebServer EC2 instance type
49 Type: String
50 Default: t2.small
51 AllowedValues:
52 - t1.micro
53 - t2.nano
54 - t2.micro
55 - t2.small
56 - t2.medium
57 - t2.large
58 - m1.small
59 - m1.medium
60 - m1.large
61 - m1.xlarge
62 - m2.xlarge
63 - m2.2xlarge
64 - m2.4xlarge
65 - m3.medium
66 - m3.large
67 - m3.xlarge
68 - m3.2xlarge
69 - m4.large
70 - m4.xlarge
71 - m4.2xlarge
72 - m4.4xlarge
73 - m4.10xlarge
74 - c1.medium
75 - c1.xlarge
76 - c3.large
77 - c3.xlarge
78 - c3.2xlarge
79 - c3.4xlarge
80 - c3.8xlarge
81 - c4.large
82 - c4.xlarge
83 - c4.2xlarge
84 - c4.4xlarge
85 - c4.8xlarge
86 - g2.2xlarge
87 - g2.8xlarge
88 - r3.large
89 - r3.xlarge
90 - r3.2xlarge
91 - r3.4xlarge
92 - r3.8xlarge
93 - i2.xlarge
94 - i2.2xlarge
95 - i2.4xlarge
96 - i2.8xlarge
97 - d2.xlarge
98 - d2.2xlarge
99 - d2.4xlarge
100 - d2.8xlarge
101 - hi1.4xlarge
102 - hs1.8xlarge
103 - cr1.8xlarge
104 - cc2.8xlarge
105 - cg1.4xlarge
106 ConstraintDescription: must be a valid EC2 instance type.
107 SSHLocation:
108 Description: ' The IP address range that can be used to SSH to the EC2 instances'
109 Type: String
110 MinLength: '9'
111 MaxLength: '18'
112 Default: 0.0.0.0/0
113 AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
114 ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
115Mappings:
116 AWSInstanceType2Arch:
117 t1.micro:
118 Arch: HVM64
119 t2.nano:
120 Arch: HVM64
121 t2.micro:
122 Arch: HVM64
123 t2.small:
124 Arch: HVM64
125 t2.medium:
126 Arch: HVM64
127 t2.large:
128 Arch: HVM64
129 m1.small:
130 Arch: HVM64
131 m1.medium:
132 Arch: HVM64
133 m1.large:
134 Arch: HVM64
135 m1.xlarge:
136 Arch: HVM64
137 m2.xlarge:
138 Arch: HVM64
139 m2.2xlarge:
140 Arch: HVM64
141 m2.4xlarge:
142 Arch: HVM64
143 m3.medium:
144 Arch: HVM64
145 m3.large:
146 Arch: HVM64
147 m3.xlarge:
148 Arch: HVM64
149 m3.2xlarge:
150 Arch: HVM64
151 m4.large:
152 Arch: HVM64
153 m4.xlarge:
154 Arch: HVM64
155 m4.2xlarge:
156 Arch: HVM64
157 m4.4xlarge:
158 Arch: HVM64
159 m4.10xlarge:
160 Arch: HVM64
161 c1.medium:
162 Arch: HVM64
163 c1.xlarge:
164 Arch: HVM64
165 c3.large:
166 Arch: HVM64
167 c3.xlarge:
168 Arch: HVM64
169 c3.2xlarge:
170 Arch: HVM64
171 c3.4xlarge:
172 Arch: HVM64
173 c3.8xlarge:
174 Arch: HVM64
175 c4.large:
176 Arch: HVM64
177 c4.xlarge:
178 Arch: HVM64
179 c4.2xlarge:
180 Arch: HVM64
181 c4.4xlarge:
182 Arch: HVM64
183 c4.8xlarge:
184 Arch: HVM64
185 g2.2xlarge:
186 Arch: HVMG2
187 g2.8xlarge:
188 Arch: HVMG2
189 r3.large:
190 Arch: HVM64
191 r3.xlarge:
192 Arch: HVM64
193 r3.2xlarge:
194 Arch: HVM64
195 r3.4xlarge:
196 Arch: HVM64
197 r3.8xlarge:
198 Arch: HVM64
199 i2.xlarge:
200 Arch: HVM64
201 i2.2xlarge:
202 Arch: HVM64
203 i2.4xlarge:
204 Arch: HVM64
205 i2.8xlarge:
206 Arch: HVM64
207 d2.xlarge:
208 Arch: HVM64
209 d2.2xlarge:
210 Arch: HVM64
211 d2.4xlarge:
212 Arch: HVM64
213 d2.8xlarge:
214 Arch: HVM64
215 hi1.4xlarge:
216 Arch: HVM64
217 hs1.8xlarge:
218 Arch: HVM64
219 cr1.8xlarge:
220 Arch: HVM64
221 cc2.8xlarge:
222 Arch: HVM64
223 AWSInstanceType2NATArch:
224 t1.micro:
225 Arch: NATHVM64
226 t2.nano:
227 Arch: NATHVM64
228 t2.micro:
229 Arch: NATHVM64
230 t2.small:
231 Arch: NATHVM64
232 t2.medium:
233 Arch: NATHVM64
234 t2.large:
235 Arch: NATHVM64
236 m1.small:
237 Arch: NATHVM64
238 m1.medium:
239 Arch: NATHVM64
240 m1.large:
241 Arch: NATHVM64
242 m1.xlarge:
243 Arch: NATHVM64
244 m2.xlarge:
245 Arch: NATHVM64
246 m2.2xlarge:
247 Arch: NATHVM64
248 m2.4xlarge:
249 Arch: NATHVM64
250 m3.medium:
251 Arch: NATHVM64
252 m3.large:
253 Arch: NATHVM64
254 m3.xlarge:
255 Arch: NATHVM64
256 m3.2xlarge:
257 Arch: NATHVM64
258 m4.large:
259 Arch: NATHVM64
260 m4.xlarge:
261 Arch: NATHVM64
262 m4.2xlarge:
263 Arch: NATHVM64
264 m4.4xlarge:
265 Arch: NATHVM64
266 m4.10xlarge:
267 Arch: NATHVM64
268 c1.medium:
269 Arch: NATHVM64
270 c1.xlarge:
271 Arch: NATHVM64
272 c3.large:
273 Arch: NATHVM64
274 c3.xlarge:
275 Arch: NATHVM64
276 c3.2xlarge:
277 Arch: NATHVM64
278 c3.4xlarge:
279 Arch: NATHVM64
280 c3.8xlarge:
281 Arch: NATHVM64
282 c4.large:
283 Arch: NATHVM64
284 c4.xlarge:
285 Arch: NATHVM64
286 c4.2xlarge:
287 Arch: NATHVM64
288 c4.4xlarge:
289 Arch: NATHVM64
290 c4.8xlarge:
291 Arch: NATHVM64
292 g2.2xlarge:
293 Arch: NATHVMG2
294 g2.8xlarge:
295 Arch: NATHVMG2
296 r3.large:
297 Arch: NATHVM64
298 r3.xlarge:
299 Arch: NATHVM64
300 r3.2xlarge:
301 Arch: NATHVM64
302 r3.4xlarge:
303 Arch: NATHVM64
304 r3.8xlarge:
305 Arch: NATHVM64
306 i2.xlarge:
307 Arch: NATHVM64
308 i2.2xlarge:
309 Arch: NATHVM64
310 i2.4xlarge:
311 Arch: NATHVM64
312 i2.8xlarge:
313 Arch: NATHVM64
314 d2.xlarge:
315 Arch: NATHVM64
316 d2.2xlarge:
317 Arch: NATHVM64
318 d2.4xlarge:
319 Arch: NATHVM64
320 d2.8xlarge:
321 Arch: NATHVM64
322 hi1.4xlarge:
323 Arch: NATHVM64
324 hs1.8xlarge:
325 Arch: NATHVM64
326 cr1.8xlarge:
327 Arch: NATHVM64
328 cc2.8xlarge:
329 Arch: NATHVM64
330 AWSRegionArch2AMI:
331 us-east-1:
332 HVM64: ami-0080e4c5bc078760e
333 HVMG2: ami-0aeb704d503081ea6
334 us-west-2:
335 HVM64: ami-01e24be29428c15b2
336 HVMG2: ami-0fe84a5b4563d8f27
337 us-west-1:
338 HVM64: ami-0ec6517f6edbf8044
339 HVMG2: ami-0a7fc72dc0e51aa77
340 eu-west-1:
341 HVM64: ami-08935252a36e25f85
342 HVMG2: ami-0d5299b1c6112c3c7
343 eu-west-2:
344 HVM64: ami-01419b804382064e4
345 HVMG2: NOT_SUPPORTED
346 eu-west-3:
347 HVM64: ami-0dd7e7ed60da8fb83
348 HVMG2: NOT_SUPPORTED
349 eu-central-1:
350 HVM64: ami-0cfbf4f6db41068ac
351 HVMG2: ami-0aa1822e3eb913a11
352 eu-north-1:
353 HVM64: ami-86fe70f8
354 HVMG2: ami-32d55b4c
355 ap-northeast-1:
356 HVM64: ami-00a5245b4816c38e6
357 HVMG2: ami-09d0e0e099ecabba2
358 ap-northeast-2:
359 HVM64: ami-00dc207f8ba6dc919
360 HVMG2: NOT_SUPPORTED
361 ap-northeast-3:
362 HVM64: ami-0b65f69a5c11f3522
363 HVMG2: NOT_SUPPORTED
364 ap-southeast-1:
365 HVM64: ami-05b3bcf7f311194b3
366 HVMG2: ami-0e46ce0d6a87dc979
367 ap-southeast-2:
368 HVM64: ami-02fd0b06f06d93dfc
369 HVMG2: ami-0c0ab057a101d8ff2
370 ap-south-1:
371 HVM64: ami-0ad42f4f66f6c1cc9
372 HVMG2: ami-0244c1d42815af84a
373 us-east-2:
374 HVM64: ami-0cd3dfa4e37921605
375 HVMG2: NOT_SUPPORTED
376 ca-central-1:
377 HVM64: ami-07423fb63ea0a0930
378 HVMG2: NOT_SUPPORTED
379 sa-east-1:
380 HVM64: ami-05145e0b28ad8e0b2
381 HVMG2: NOT_SUPPORTED
382 cn-north-1:
383 HVM64: ami-053617c9d818c1189
384 HVMG2: NOT_SUPPORTED
385 cn-northwest-1:
386 HVM64: ami-0f7937761741dc640
387 HVMG2: NOT_SUPPORTED
388Resources:
389 WebServerInstance:
390 Type: 'AWS::EC2::Instance'
391 Metadata:
392 'AWS::CloudFormation::Init':
393 configSets:
394 InstallAndRun:
395 - Install
396 - Configure
397 Install:
398 packages:
399 yum:
400 mysql: []
401 mysql-server: []
402 mysql-libs: []
403 httpd: []
404 php: []
405 php-mysql: []
406 files:
407 /var/www/html/index.php:
408 content: !Join
409 - ''
410 - - |
411 <html>
412 - |2
413 <head>
414 - |2
415 <title>AWS CloudFormation PHP Sample</title>
416 - |2
417 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
418 - |2
419 </head>
420 - |2
421 <body>
422 - |2
423 <h1>Welcome to the AWS CloudFormation PHP Sample</h1>
424 - |2
425 <p/>
426 - |2
427 <?php
428 - |2
429 // Print out the current data and time
430 - |2
431 print "The Current Date and Time is: <br/>";
432 - |2
433 print date("g:i A l, F j Y.");
434 - |2
435 ?>
436 - |2
437 <p/>
438 - |2
439 <?php
440 - |2
441 // Setup a handle for CURL
442 - |2
443 $curl_handle=curl_init();
444 - |2
445 curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
446 - |2
447 curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
448 - |2
449 // Get the hostname of the intance from the instance metadata
450 - |2
451 curl_setopt($curl_handle,CURLOPT_URL,'http://169.254.169.254/latest/meta-data/public-hostname');
452 - |2
453 $hostname = curl_exec($curl_handle);
454 - |2
455 if (empty($hostname))
456 - |2
457 {
458 - |2
459 print "Sorry, for some reason, we got no hostname back <br />";
460 - |2
461 }
462 - |2
463 else
464 - |2
465 {
466 - |2
467 print "Server = " . $hostname . "<br />";
468 - |2
469 }
470 - |2
471 // Get the instance-id of the intance from the instance metadata
472 - |2
473 curl_setopt($curl_handle,CURLOPT_URL,'http://169.254.169.254/latest/meta-data/instance-id');
474 - |2
475 $instanceid = curl_exec($curl_handle);
476 - |2
477 if (empty($instanceid))
478 - |2
479 {
480 - |2
481 print "Sorry, for some reason, we got no instance id back <br />";
482 - |2
483 }
484 - |2
485 else
486 - |2
487 {
488 - |2
489 print "EC2 instance-id = " . $instanceid . "<br />";
490 - |2
491 }
492 - |2
493 $Database = "localhost";
494 - ' $DBUser = "'
495 - !Ref DBUser
496 - |
497 ";
498 - ' $DBPassword = "'
499 - !Ref DBPassword
500 - |
501 ";
502 - |2
503 print "Database = " . $Database . "<br />";
504 - |2
505 $dbconnection = mysql_connect($Database, $DBUser, $DBPassword)
506 - |2
507 or die("Could not connect: " . mysql_error());
508 - |2
509 print ("Connected to $Database successfully");
510 - |2
511 mysql_close($dbconnection);
512 - |2
513 ?>
514 - |2
515 <h2>PHP Information</h2>
516 - |2
517 <p/>
518 - |2
519 <?php
520 - |2
521 phpinfo();
522 - |2
523 ?>
524 - |2
525 </body>
526 - |
527 </html>
528 mode: '000600'
529 owner: apache
530 group: apache
531 /tmp/setup.mysql:
532 content: !Join
533 - ''
534 - - 'CREATE DATABASE '
535 - !Ref DBName
536 - |
537 ;
538 - 'GRANT ALL ON '
539 - !Ref DBName
540 - .* TO '
541 - !Ref DBUser
542 - '''@localhost IDENTIFIED BY '''
543 - !Ref DBPassword
544 - |
545 ';
546 mode: '000400'
547 owner: root
548 group: root
549 /etc/cfn/cfn-hup.conf:
550 content: !Join
551 - ''
552 - - |
553 [main]
554 - stack=
555 - !Ref 'AWS::StackId'
556 - |+
557
558 - region=
559 - !Ref 'AWS::Region'
560 - |+
561
562 mode: '000400'
563 owner: root
564 group: root
565 /etc/cfn/hooks.d/cfn-auto-reloader.conf:
566 content: !Join
567 - ''
568 - - |
569 [cfn-auto-reloader-hook]
570 - |
571 triggers=post.update
572 - >
573 path=Resources.WebServerInstance.Metadata.AWS::CloudFormation::Init
574 - 'action=/opt/aws/bin/cfn-init -v '
575 - ' --stack '
576 - !Ref 'AWS::StackName'
577 - ' --resource WebServerInstance '
578 - ' --configsets InstallAndRun '
579 - ' --region '
580 - !Ref 'AWS::Region'
581 - |+
582
583 - |
584 runas=root
585 mode: '000400'
586 owner: root
587 group: root
588 services:
589 sysvinit:
590 mysqld:
591 enabled: 'true'
592 ensureRunning: 'true'
593 httpd:
594 enabled: 'true'
595 ensureRunning: 'true'
596 cfn-hup:
597 enabled: 'true'
598 ensureRunning: 'true'
599 files:
600 - /etc/cfn/cfn-hup.conf
601 - /etc/cfn/hooks.d/cfn-auto-reloader.conf
602 Configure:
603 commands:
604 01_set_mysql_root_password:
605 command: !Join
606 - ''
607 - - mysqladmin -u root password '
608 - !Ref DBRootPassword
609 - ''''
610 test: !Join
611 - ''
612 - - '$(mysql '
613 - !Ref DBName
614 - ' -u root --password='''
615 - !Ref DBRootPassword
616 - ''' >/dev/null 2>&1 </dev/null); (( $? != 0 ))'
617 02_create_database:
618 command: !Join
619 - ''
620 - - mysql -u root --password='
621 - !Ref DBRootPassword
622 - ''' < /tmp/setup.mysql'
623 test: !Join
624 - ''
625 - - '$(mysql '
626 - !Ref DBName
627 - ' -u root --password='''
628 - !Ref DBRootPassword
629 - ''' >/dev/null 2>&1 </dev/null); (( $? != 0 ))'
630 'AWS::CloudFormation::Designer':
631 id: 874ecd46-54c4-45f3-855a-db8f5bfdcb29
632 Properties:
633 ImageId: !FindInMap
634 - AWSRegionArch2AMI
635 - !Ref 'AWS::Region'
636 - !FindInMap
637 - AWSInstanceType2Arch
638 - !Ref InstanceType
639 - Arch
640 InstanceType: !Ref InstanceType
641 SecurityGroups:
642 - !Ref WebServerSecurityGroup
643 KeyName: !Ref KeyName
644 UserData: !Base64
645 'Fn::Join':
646 - ''
647 - - |
648 #!/bin/bash -xe
649 - |
650 yum update -y aws-cfn-bootstrap
651 - |
652 # Install the files and packages from the metadata
653 - '/opt/aws/bin/cfn-init -v '
654 - ' --stack '
655 - !Ref 'AWS::StackName'
656 - ' --resource WebServerInstance '
657 - ' --configsets InstallAndRun '
658 - ' --region '
659 - !Ref 'AWS::Region'
660 - |+
661
662 - |
663 # Signal the status from cfn-init
664 - '/opt/aws/bin/cfn-signal -e $? '
665 - ' --stack '
666 - !Ref 'AWS::StackName'
667 - ' --resource WebServerInstance '
668 - ' --region '
669 - !Ref 'AWS::Region'
670 - |+
671
672 CreationPolicy:
673 ResourceSignal:
674 Timeout: PT5M
675 WebServerSecurityGroup:
676 Type: 'AWS::EC2::SecurityGroup'
677 Properties:
678 GroupDescription: Enable HTTP access via port 80
679 SecurityGroupIngress:
680 - IpProtocol: tcp
681 FromPort: '80'
682 ToPort: '80'
683 CidrIp: 0.0.0.0/0
684 - IpProtocol: tcp
685 FromPort: '22'
686 ToPort: '22'
687 CidrIp: !Ref SSHLocation
688 Metadata:
689 'AWS::CloudFormation::Designer':
690 id: df8dc4da-3b14-4259-a021-5876a176bc46
691Outputs:
692 WebsiteURL:
693 Description: URL for newly created LAMP stack
694 Value: !Join
695 - ''
696 - - 'http://'
697 - !GetAtt
698 - WebServerInstance
699 - PublicDnsName
700Metadata:
701 'AWS::CloudFormation::Designer':
702 df8dc4da-3b14-4259-a021-5876a176bc46:
703 size:
704 width: 60
705 height: 60
706 position:
707 x: 60
708 'y': 90
709 z: 1
710 embeds: []
711 874ecd46-54c4-45f3-855a-db8f5bfdcb29:
712 size:
713 width: 60
714 height: 60
715 position:
716 x: 180
717 'y': 90
718 z: 1
719 embeds: []
720 isassociatedwith:
721 - df8dc4da-3b14-4259-a021-5876a176bc46
722