-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoscaling.yaml
108 lines (96 loc) · 2.47 KB
/
autoscaling.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
AWSTemplateFormatVersion: "2010-09-09"
Description: EC2 for webserver
Parameters:
Key:
Description: KeyPair
Type: AWS::EC2::KeyPair::KeyName
VPC:
Description: VPC
Type: AWS::EC2::VPC::Id
WebSG:
Description: SG for Web Server
Type: AWS::EC2::SecurityGroup::Id
PublicSubnet1:
Description: public 1
Type: AWS::EC2::Subnet::Id
PublicSubnet2:
Description: public 2
Type: AWS::EC2::Subnet::Id
PrivateSubnet1:
Description: private 1
Type: AWS::EC2::Subnet::Id
PrivateSubnet2:
Description: private 2
Type: AWS::EC2::Subnet::Id
Resources:
LC:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
ImageId: ami-017459178eade98f5
InstanceType: t3.micro
InstanceMonitoring: true
KeyName: !Ref Key
LaunchConfigurationName: webserverLC
SecurityGroups:
- !Ref WebSG
ALB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: webserverALB
Type: application
SecurityGroups:
- !Ref WebSG
Subnets:
- !Ref PublicSubnet1
- !Ref PublicSubnet2
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
VpcId: !Ref VPC
Name: webtest
Port: 80
Protocol: HTTP
VpcId: !Ref VPC
HealthCheckEnabled: true
HealthCheckIntervalSeconds: 10
HealthCheckPath: /
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 5
HealthyThresholdCount: 5
UnhealthyThresholdCount: 2
ALBListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroup
LoadBalancerArn: !Ref ALB
Port: 80
Protocol: HTTP
ASG:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AutoScalingGroupName: webserverASG
VPCZoneIdentifier:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
Cooldown: 10
LaunchConfigurationName: !Ref LC
MaxSize: 4
MinSize: 2
DesiredCapacity: 2
TargetGroupARNs:
- !Ref TargetGroup
Tags:
- Key: Name
Value: web-asg
PropagateAtLaunch: true
ASGPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AutoScalingGroupName: !Ref ASG
PolicyType: TargetTrackingScaling
TargetTrackingConfiguration:
PredefinedMetricSpecification:
PredefinedMetricType: ASGAverageCPUUtilization
TargetValue: 45