-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-AutoScaling.yml
executable file
·159 lines (147 loc) · 4.37 KB
/
4-AutoScaling.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
Description: This template crete the autoscaling group
Parameters:
EnvironmentName:
Description: An environment name that will be prefixed to resource names
Type: String
Default: PROD
# AutoScalling
Resources:
AppAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
TargetGroupARNs:
- Fn::ImportValue: AppDefaultTargetGroup
VPCZoneIdentifier:
- Fn::ImportValue: PrivateSubnet1
- Fn::ImportValue: PrivateSubnet2
LaunchConfigurationName: !Ref LaunchConfig
MinSize: 1
MaxSize: 1
DesiredCapacity: 1
Tags:
- Key: Name
Value: !Sub ${EnvironmentName} APP ECS host
PropagateAtLaunch: true
CreationPolicy:
ResourceSignal:
Timeout: PT15M
UpdatePolicy:
AutoScalingRollingUpdate:
MinInstancesInService: 1
MaxBatchSize: 1
PauseTime: PT1M
SuspendProcesses:
- HealthCheck
- ReplaceUnhealthy
- AZRebalance
- AlarmNotification
- ScheduledActions
WaitOnResourceSignals: true
AppScaleUpPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName:
Ref: AppAutoScalingGroup
Cooldown: '1'
ScalingAdjustment: '1'
AppCPUAlarmHigh:
Type: AWS::CloudWatch::Alarm
Properties:
EvaluationPeriods: '1'
Statistic: Average
Threshold: '10'
AlarmDescription: Alarm if CPU too high or metric disappears indicating instance is down
Period: '60'
AlarmActions:
- Ref: AppScaleUpPolicy
Namespace: AWS/EC2
Dimensions:
- Name: AppAutoScalingGroup
Value:
Ref: AppAutoScalingGroup
ComparisonOperator: GreaterThanThreshold
MetricName: CPUUtilization
WebAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
TargetGroupARNs:
- Fn::ImportValue: WebDefaultTargetGroup
VPCZoneIdentifier:
- Fn::ImportValue: PrivateSubnet1
- Fn::ImportValue: PrivateSubnet2
LaunchConfigurationName: !Ref LaunchConfig
MinSize: 1
MaxSize: 1
DesiredCapacity: 1
Tags:
- Key: Name
Value: !Sub ${EnvironmentName} WEB ECS host
PropagateAtLaunch: true
CreationPolicy:
ResourceSignal:
Timeout: PT15M
UpdatePolicy:
AutoScalingRollingUpdate:
MinInstancesInService: 1
MaxBatchSize: 1
PauseTime: PT1M
SuspendProcesses:
- HealthCheck
- ReplaceUnhealthy
- AZRebalance
- AlarmNotification
- ScheduledActions
WaitOnResourceSignals: true
WebScaleUpPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName:
Ref: WebAutoScalingGroup
Cooldown: '1'
ScalingAdjustment: '1'
WebCPUAlarmHigh:
Type: AWS::CloudWatch::Alarm
Properties:
EvaluationPeriods: '1'
Statistic: Average
Threshold: '10'
AlarmDescription: Alarm if CPU too high or metric disappears indicating instance is down
Period: '60'
AlarmActions:
- Ref: WebScaleUpPolicy
Namespace: AWS/EC2
Dimensions:
- Name: WebAutoScalingGroup
Value:
Ref: WebAutoScalingGroup
ComparisonOperator: GreaterThanThreshold
MetricName: CPUUtilization
#Launch Config
LaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
LaunchConfigurationName: AppApplicationServer
AssociatePublicIpAddress: false
KeyName: aws_key_pair
ImageId: ami-048a01c78f7bae4aa
InstanceMonitoring: false
InstanceType: t2.nano
SecurityGroups:
- Fn::ImportValue: AppSecurityGroup
BlockDeviceMappings:
- DeviceName: "/dev/sda1"
Ebs:
VolumeSize: "50"
VolumeType: "io1"
Iops: 200
DeleteOnTermination: "true"
#OutPut
Outputs:
AppAutoScalingGroup:
Description: AppAutoScalingGroup
Value: !Ref AppAutoScalingGroup
WebAutoScalingGroup:
Description: WebAutoScalingGroup
Value: !Ref WebAutoScalingGroup