-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path04-EC2-Instance-wordpress.yml
818 lines (818 loc) · 29.5 KB
/
04-EC2-Instance-wordpress.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
---
AWSTemplateFormatVersion: 2010-09-09
Description: >-
AWS CloudFormation Sample Template Sample template EIP_With_Association: This
template shows how to associate an Elastic IP address with an Amazon EC2
instance - you can use this same technique to associate an EC2 instance with
an Elastic IP Address that is not created inside the template by replacing the
EIP reference in the AWS::EC2::EIPAssoication resource type with the IP
address of the external EIP. **WARNING** This template creates an Amazon EC2
instance and an Elastic IP Address. You will be billed for the AWS resources
used if you create a stack from this template.
Parameters:
InstanceType:
Description: WebServer EC2 instance type
Type: String
Default: t2.small
AllowedValues:
- t1.micro
- t2.nano
- t2.micro
- t2.small
- t2.medium
- t2.large
ConstraintDescription: must be a valid EC2 instance type.
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
Type: 'AWS::EC2::KeyPair::KeyName'
ConstraintDescription: must be the name of an existing EC2 KeyPair.
Default: t2.small
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.
HTTPLocation:
Description: The IP address range that will access website on 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.
ImageId:
Type: String
Default: ami-40142d25
Description: It's an AWS Linux-AMI with preinstalled tools and packages
ApplicationID:
Type: String
Default: demotest
MinLength: 3
MaxLength: 30
AllowedPattern: "^[a-z0-9]*"
Description: Enter Application ID
Region:
Type: String
Default: us-east-2
Description: Region in which VPC will be launched
AllowedValues:
- us-east-2
- us-east-1
Environment:
Type: String
Default: Dev
MinLength: 1
MaxLength: 20
Description: Enter The Environment
AllowedValues:
- Dev
- OAT
- UAT
- Pre-Production
- Production
BackUp:
Type: String
Default: yes
MinLength: 2
MaxLength: 5
AllowedPattern: "^[a-z]*"
AllowedValues:
- yes
- no
Description: Choose yes if you want to create Backup of the resource else enter no
EBSBackup:
Type: String
Default: yes
MinLength: 2
MaxLength: 5
AllowedPattern: "^[a-z]*"
AllowedValues:
- yes
- no
Description: Choose yes if you want to create EBS Backup of the resource else enter no
AMIBackup:
Type: String
Default: yes
MinLength: 2
MaxLength: 5
AllowedPattern: "^[a-z]*"
AllowedValues:
- yes
- no
Description: Choose yes if you want to create AMI Backup of the resource else enter no
ServerType:
Type: String
Default: Linux
MinLength: 3
MaxLength: 9
Description: Enter ServerType
RoleName:
Type: String
Default: IT-Admin-Role
LinuxParameter:
Type: String
Default: AmazonCloudWatch_Linux
ApplicationFunction:
Type: String
MinLength: 3
MaxLength: 26
Default: travel
Description: Select the key functionality of Application
Severity1:
Type: String
MinLength: 1
MaxLength: 12
Default: high
Description: 'The severity of Alarm'
ApplicationDescription:
Type: String
MinLength: 3
MaxLength: 30
Default: webapp
AllowedPattern: "^[a-zA-Z0-9]*"
Description: Enter Application descripion in few words
Resources:
EC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: !Ref InstanceType
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
GroupSet:
- !Ref SecurityGroup
DeviceIndex: '0'
DeleteOnTermination: 'true'
SubnetId:
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref Region , 'subnet-id-az1' ] ]
KeyName: !Ref KeyName
ImageId: !Ref ImageId
IamInstanceProfile: !Ref IamInstanceProfile
Tags:
- Key: "Name"
Value: !Join
- '-'
- - !Ref ApplicationID
- !Ref Environment
- webserver
- Key: Environment
Value: !Ref Environment
- Key: AppID
Value: !Ref ApplicationID
- Key: BackUp
Value: !Ref BackUp
- Key : EBSBackup
Value: !Ref EBSBackup
- Key: AMIBackup
Value: !Ref AMIBackup
UserData:
Fn::Base64:
!Sub |
#!/bin/bash
sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd wget unzip zip
sudo service httpd start
sudo chkconfig httpd on
sudo echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
sudo service mysqld start
sudo chkconfig mysqld on
sudo wget -qO- https://wordpress.org/latest.tar.gz | tar xvz -C /var/www/html/
sudo wget -O /var/www/html/wordpress/wp-config.php https://s3.us-east-2.amazonaws.com/mywordpressfolder/wp-config.php
sudo mysql -e "create user wordpress@'%' identified by 'Thunder@1234';"
sudo mysql -e "grant all on *.* to wordpress@'localhost' identified by 'Thunder@1234';"
sudo mysql -e "create database wordpressdb;"
sudo mysql -e "flush privileges;"
sudo find /var/www -type f -exec sudo chmod 0664 {} \;
sudo /usr/bin/easy_install --script-dir /opt/aws/bin https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
sudo wget https://s3.amazonaws.com/amazoncloudwatch-agent/linux/amd64/latest/AmazonCloudWatchAgent.zip
sudo unzip AmazonCloudWatchAgent.zip
./install.sh
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${LinuxParameter} -s
IamInstanceProfile:
Type: "AWS::IAM::InstanceProfile"
Properties:
Path: "/"
Roles:
- !Ref RoleName
SecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId:
Fn::ImportValue: !Join [ "-" , [ !Ref ApplicationID , !Ref Environment , !Ref Region , 'vpc-id' ] ]
GroupDescription: Enable SSH-HTTP Ports
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref SSHLocation
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: !Ref HTTPLocation
Tags:
- Key: Name
Value: !Join
- '-'
- - !Ref ApplicationID
- !Ref Environment
- 'webserver-sg'
IPAddress:
Type: 'AWS::EC2::EIP'
IPAssoc:
Type: 'AWS::EC2::EIPAssociation'
Properties:
InstanceId: !Ref EC2Instance
EIP: !Ref IPAddress
CPUAlarmHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: CPU High alarm of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'cpu-alert' ] ]
MetricName: CPUUtilization
AlarmName: !Join [ "-" , [ !Ref Environment , ApplicationDescription, 'cpu' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '70'
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
NetworkPacketsOutHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Network Packets Out of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'network-alert' ] ]
MetricName: NetworkPacketsOut
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'net-pkt-out' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '1073741824'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
NetworkPacketsInHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Network Packets In of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'network-alert' ] ]
MetricName: NetworkPacketsIn
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'net-pkt-in' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '1073741824'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
NetworkInHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Network traffic In of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'network-alert' ] ]
MetricName: NetworkIn
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'net-in' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Average
Period: '300'
EvaluationPeriods: '1'
Threshold: '1073741824'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
NetworkOutHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Network traffic Out of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'network-alert' ] ]
MetricName: NetworkOut
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'net-out' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Average
Period: '300'
EvaluationPeriods: '1'
Threshold: '1073741824'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
DiskWriteBytesHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk Write Bytes of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: DiskWriteBytes
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-write-byte' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Average
Period: '300'
EvaluationPeriods: '1'
Threshold: '500000000'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
DiskReadBytesHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk Read Bytes of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: DiskReadBytes
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-read-byte' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Average
Period: '300'
EvaluationPeriods: '1'
Threshold: '100000000'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
DiskReadOpsHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk Read Operations on Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: DiskReadOps
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-read-ops' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '500000000'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
DiskWriteOpsHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk Write Operations on Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: DiskWriteOps
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-write-ops' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '500000000'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
StatusCheckFailedHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Status Check Failed of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'status-alert' ] ]
MetricName: StatusCheckFailed
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'stat-chk-fail' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Minimum
Period: '300'
EvaluationPeriods: '1'
Threshold: '3'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
StatusCheckFailedSystemHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Status Check Failed for System of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'status-alert' ] ]
MetricName: StatusCheckFailed_System
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'stat-chk-fail-sys' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Minimum
Period: '300'
EvaluationPeriods: '1'
Threshold: '3'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
StatusCheckFailedInstanceHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Status Check Failed for Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'status-alert' ] ]
MetricName: StatusCheckFailed_Instance
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'stat-chk-fail-Ins' , !Ref Severity1 ] ]
Namespace: AWS/EC2
Statistic: Minimum
Period: '300'
EvaluationPeriods: '1'
Threshold: '3'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
diskinodesfreeHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk Nodes free for an Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: disk_inodes_free
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-inode-free' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '6000000'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: path
Value: '/'
- Name: device
Value: 'rootfs'
- Name: fstype
Value: 'rootfs'
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
diskusedpercentHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk used in percent of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: disk_used_percent
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-percent' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '80'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: path
Value: '/'
- Name: device
Value: 'rootfs'
- Name: fstype
Value: 'rootfs'
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
diskiotimeHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: Disk io consumed in milliseconds of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: diskio_io_time
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-io' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '10'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: name
Value: 'xvda'
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
diskioreadbyteHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk io read bytes of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: diskio_read_bytes
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-io-read-byte' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '50000000'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: name
Value: 'xvda'
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
diskioreadHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk io read of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: diskio_reads
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-io-read' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '500'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: name
Value: 'xvda'
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
diskiowriteHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk io write of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: diskio_writes
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-io-write' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '300'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: name
Value: 'xvda'
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
diskiowritebyteHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Disk io read write of Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'disk-alert' ] ]
MetricName: diskio_write_bytes
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'disk-io-write-byte' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '25000000'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: name
Value: 'xvda'
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
memusedpercentHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Percent of memory used in Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'memory-alert' ] ]
MetricName: mem_used_percent
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'mem-used-percent' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Average
Period: '300'
EvaluationPeriods: '1'
Threshold: '80'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
swapusedpercentHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High Percent of swap used in Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'memory-alert' ] ]
MetricName: swap_used_percent
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'swap-used-percent' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Average
Period: '300'
EvaluationPeriods: '1'
Threshold: '80'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
netstattcptimewaitHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High time wait of network statistics used in Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'network-alert' ] ]
MetricName: netstat_tcp_time_wait
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'netstat-tcp-time-wait' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Average
Period: '300'
EvaluationPeriods: '1'
Threshold: '800'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
netstattcpestablishedHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High time established of network tcp used in Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'network-alert' ] ]
MetricName: netstat_tcp_established
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'netstat-tcp-established' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Average
Period: '300'
EvaluationPeriods: '1'
Threshold: '800'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
cpuusageidleHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High time CPU is in Idle state in Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'cpu-alert' ] ]
MetricName: cpu_usage_idle
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'cpu-idle' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '30'
ComparisonOperator: LessThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
- Name: cpu
Value: 'cpu0'
cpuusageiowaitHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High time CPU usage iowait in Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'cpu-alert' ] ]
MetricName: cpu_usage_iowait
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'cpu-iowait' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '70'
ComparisonOperator: LessThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
- Name: cpu
Value: 'cpu0'
cpuusagesystemHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High time CPU usage system in Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'cpu-alert' ] ]
MetricName: cpu_usage_system
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'cpu-system-usage' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '70'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
- Name: cpu
Value: 'cpu0'
cpuusageuserHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: High time CPU usage user in Instance
AlarmActions:
-
Fn::ImportValue: !Join [ "-" , [ !Ref Environment , !Ref ApplicationFunction , !Ref ApplicationDescription ,'cpu-alert' ] ]
MetricName: cpu_usage_system
AlarmName: !Join [ "-" , [ !Ref Environment , !Ref ApplicationDescription, 'cpu-user-usage' , !Ref Severity1 ] ]
Namespace: CWAgent
Statistic: Maximum
Period: '300'
EvaluationPeriods: '1'
Threshold: '70'
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: InstanceId
Value: !Ref EC2Instance
- Name: ImageId
Value: !Ref ImageId
- Name: InstanceType
Value: !Ref InstanceType
- Name: cpu
Value: 'cpu0'
Outputs:
JumpHostSecurityGroup:
Description: Security Id for JumpHostSecurityGroup
Value: !Ref SecurityGroup
Export:
Name: !Join
- '-'
- - !Ref Environment
- !Ref Region
- Webserver-SG
InstanceId:
Description: InstanceId of the newly created EC2 instance
Value: !Ref EC2Instance
InstanceIPAddress:
Description: IP address of the newly created EC2 instance
Value: !Ref IPAddress