-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkafka-hands-on-cloudformation-template0.yml
163 lines (163 loc) · 4.78 KB
/
kafka-hands-on-cloudformation-template0.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
AWSTemplateFormatVersion: "2010-09-09"
Description: "Template to start EC2 instance from image containing kafka and other tools with an EIP and a proper security group"
Parameters:
ParamEC2:
Type: String
Resources:
UpScalingPolicy:
Type: "AWS::AutoScaling::ScalingPolicy"
Properties:
AdjustmentType: "ChangeInCapacity"
AutoScalingGroupName: !Ref MyAutoScalingGroup
Cooldown: "300"
PolicyType: "SimpleScaling"
ScalingAdjustment: '1'
DownScalingPolicy:
Type: "AWS::AutoScaling::ScalingPolicy"
Properties:
AdjustmentType: "ChangeInCapacity"
AutoScalingGroupName: !Ref MyAutoScalingGroup
Cooldown: "300"
PolicyType: "SimpleScaling"
ScalingAdjustment: '-1'
CPUAlarmHigh:
Type: "AWS::CloudWatch::Alarm"
Properties:
AlarmDescription: "Scale-up if CPU > 90% for 10 minutes"
MetricName: "CPUUtilization"
Namespace: "AWS/EC2"
Statistic: "Average"
Period: "300"
EvaluationPeriods: "2"
Threshold: "90"
AlarmActions: [ Ref: UpScalingPolicy ]
Dimensions:
-
Name: "AutoScalingGroupName"
Value:
Ref: MyAutoScalingGroup
ComparisonOperator: "GreaterThanThreshold"
CPUAlarmDown:
Type: "AWS::CloudWatch::Alarm"
Properties:
AlarmDescription: "Scale-up if CPU < 70% for 10 minutes"
MetricName: "CPUUtilization"
Namespace: "AWS/EC2"
Statistic: "Average"
Period: "300"
EvaluationPeriods: "2"
Threshold: "90"
AlarmActions: [ Ref: DownScalingPolicy ]
Dimensions:
-
Name: "AutoScalingGroupName"
Value:
Ref: MyAutoScalingGroup
ComparisonOperator: "LessThanThreshold"
MyAutoScalingGroup:
Type: "AWS::AutoScaling::AutoScalingGroup"
Properties:
AvailabilityZones:
Fn::GetAZs:
Ref: "AWS::Region"
MaxSize: 4
MinSize: 1
InstanceId:
- !Ref EC2Instance1
- !Ref EC2Instance2
- !Ref EC2Instance3
- !Ref EC2Instance4
- !Ref EC2Instance5
- !Ref EC2Instance6
VPCZoneIdentifier:
- subnet-4520f632
- subnet-98633cde
- subnet-76d87013
EC2Instance1:
Type: "AWS::EC2::Instance"
Properties:
ImageId:
Ref: ParamEC2
KeyName: "NIG-NPA-kafka-pilot"
InstanceType: t2.small
SecurityGroupIds:
- !Ref HandsOnSecurityGroup
EC2Instance2:
Type: "AWS::EC2::Instance"
Properties:
ImageId:
Ref: ParamEC2
KeyName: "NIG-NPA-kafka-pilot"
InstanceType: t2.small
SecurityGroupIds:
- !Ref HandsOnSecurityGroup
EC2Instance3:
Type: "AWS::EC2::Instance"
Properties:
ImageId:
Ref: ParamEC2
KeyName: "NIG-NPA-kafka-pilot"
InstanceType: t2.small
SecurityGroupIds:
- !Ref HandsOnSecurityGroup
EC2Instance4:
Type: "AWS::EC2::Instance"
Properties:
ImageId:
Ref: ParamEC2
KeyName: "NIG-NPA-kafka-pilot"
InstanceType: t2.small
SecurityGroupIds:
- !Ref HandsOnSecurityGroup
EC2Instance5:
Type: "AWS::EC2::Instance"
Properties:
ImageId:
Ref: ParamEC2
KeyName: "NIG-NPA-kafka-pilot"
InstanceType: t2.small
SecurityGroupIds:
- !Ref HandsOnSecurityGroup
EC2Instance6:
Type: "AWS::EC2::Instance"
Properties:
ImageId:
Ref: ParamEC2
KeyName: "NIG-NPA-kafka-pilot"
InstanceType: t2.small
SecurityGroupIds:
- !Ref HandsOnSecurityGroup
HandsOnSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Security group opened to all ips for the hands-on duration"
SecurityGroupEgress:
- IpProtocol: '-1'
FromPort: '0'
ToPort: '0'
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '0'
ToPort: '65535'
CidrIp: 0.0.0.0/0
VpcId: "vpc-4f7bad2a"
Outputs:
PublicIp1:
Value: !GetAtt EC2Instance1.PublicIp
Description: "Public ip of the set up EC2 Instance"
PublicIp2:
Value: !GetAtt EC2Instance2.PublicIp
Description: "Public ip of the set up EC2 Instance"
PublicIp3:
Value: !GetAtt EC2Instance3.PublicIp
Description: "Public ip of the set up EC2 Instance"
PublicIp4:
Value: !GetAtt EC2Instance4.PublicIp
Description: "Public ip of the set up EC2 Instance"
PublicIp5:
Value: !GetAtt EC2Instance5.PublicIp
Description: "Public ip of the set up EC2 Instance"
PublicIp6:
Value: !GetAtt EC2Instance6.PublicIp
Description: "Public ip of the set up EC2 Instance"