-
Notifications
You must be signed in to change notification settings - Fork 0
/
MSKTemplate02.yaml
321 lines (301 loc) · 8.77 KB
/
MSKTemplate02.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
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
AWSTemplateFormatVersion: 2010-09-09
Parameters:
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
Type: 'AWS::EC2::KeyPair::KeyName'
ConstraintDescription: Can contain only ASCII characters.
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
Mappings:
SubnetConfig:
VPC:
CIDR: 10.0.0.0/16
PublicOne:
CIDR: 10.0.0.0/24
PrivateOne:
CIDR: 10.0.1.0/24
PrivateTwo:
CIDR: 10.0.2.0/24
PrivateThree:
CIDR: 10.0.3.0/24
RegionAMI:
us-east-1:
HVM64: ami-0c6b1d09930fac512
us-west-2:
HVM64: ami-0cb72367e98845d43
Resources:
VPC:
Type: 'AWS::EC2::VPC'
Properties:
EnableDnsSupport: true
EnableDnsHostnames: true
CidrBlock: !FindInMap
- SubnetConfig
- VPC
- CIDR
Tags:
- Key: Name
Value: MMVPC
PublicSubnetOne:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone: !Select
- 0
- !GetAZs
Ref: 'AWS::Region'
VpcId: !Ref VPC
CidrBlock: !FindInMap
- SubnetConfig
- PublicOne
- CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: MMPublicSubnet
PrivateSubnetOne:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone: !Select
- 0
- !GetAZs
Ref: 'AWS::Region'
VpcId: !Ref VPC
CidrBlock: !FindInMap
- SubnetConfig
- PrivateOne
- CIDR
Tags:
- Key: Name
Value: MMPrivateSubnetOne
PrivateSubnetTwo:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone: !Select
- 1
- !GetAZs
Ref: 'AWS::Region'
VpcId: !Ref VPC
CidrBlock: !FindInMap
- SubnetConfig
- PrivateTwo
- CIDR
Tags:
- Key: Name
Value: MMPrivateSubnetTwo
PrivateSubnetThree:
Type: 'AWS::EC2::Subnet'
Properties:
AvailabilityZone: !Select
- 2
- !GetAZs
Ref: 'AWS::Region'
VpcId: !Ref VPC
CidrBlock: !FindInMap
- SubnetConfig
- PrivateThree
- CIDR
Tags:
- Key: Name
Value: MMPrivateSubnetThree
InternetGateway:
Type: 'AWS::EC2::InternetGateway'
GatewayAttachement:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
PublicRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
PublicRoute:
Type: 'AWS::EC2::Route'
DependsOn: GatewayAttachement
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnetOneRouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
SubnetId: !Ref PublicSubnetOne
RouteTableId: !Ref PublicRouteTable
PrivateRouteTable:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref VPC
PrivateSubnetOneRouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PrivateRouteTable
SubnetId: !Ref PrivateSubnetOne
PrivateSubnetTwoRouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PrivateRouteTable
SubnetId: !Ref PrivateSubnetTwo
PrivateSubnetThreeRouteTableAssociation:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref PrivateRouteTable
SubnetId: !Ref PrivateSubnetThree
KafkaClientInstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable SSH access via port 22
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref SSHLocation
MSKSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable access via port 2181,9094 and 9092 from clientInstance
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 2181
ToPort: 2181
SourceSecurityGroupId: !GetAtt
- KafkaClientInstanceSecurityGroup
- GroupId
- IpProtocol: tcp
FromPort: 9094
ToPort: 9094
SourceSecurityGroupId: !GetAtt
- KafkaClientInstanceSecurityGroup
- GroupId
- IpProtocol: tcp
FromPort: 9092
ToPort: 9092
SourceSecurityGroupId: !GetAtt
- KafkaClientInstanceSecurityGroup
- GroupId
KafkaClientEC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: t3.small
KeyName: !Ref KeyName
IamInstanceProfile: !Ref EC2InstanceProfile
AvailabilityZone: !Select
- 0
- !GetAZs
Ref: 'AWS::Region'
SubnetId: !Ref PublicSubnetOne
SecurityGroupIds:
- !GetAtt
- KafkaClientInstanceSecurityGroup
- GroupId
ImageId: !FindInMap
- RegionAMI
- !Ref 'AWS::Region'
- HVM64
Tags:
- Key: Name
Value: KafkaClientInstance
UserData: !Base64 >
#!/bin/bash
yum update -y
yum install python3.7 -y
yum install java-1.8.0-openjdk-devel -y
yum erase awscli -y
cd /home/ec2-user
echo "export PATH=.local/bin:$PATH" >> .bash_profile
mkdir kafka
mkdir mm
cd kafka
wget https://archive.apache.org/dist/kafka/2.2.1/kafka_2.12-2.2.1.tgz
tar -xzf kafka_2.12-2.2.1.tgz
cd /home/ec2-user
wget https://bootstrap.pypa.io/get-pip.py
su -c "python3.7 get-pip.py --user" -s /bin/sh ec2-user
su -c "/home/ec2-user/.local/bin/pip3 install boto3 --user" -s /bin/sh
ec2-user
su -c "/home/ec2-user/.local/bin/pip3 install awscli --user" -s /bin/sh
ec2-user
chown -R ec2-user ./kafka
chgrp -R ec2-user ./kafka
chown -R ec2-user ./mm
chgrp -R ec2-user ./mm
EC2Role:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/AmazonMSKFullAccess'
- 'arn:aws:iam::aws:policy/AWSCloudFormationReadOnlyAccess'
EC2InstanceProfile:
Type: 'AWS::IAM::InstanceProfile'
Properties:
InstanceProfileName: EC2MSKCFProfile
Roles:
- !Ref EC2Role
MSKCluster:
Type: 'AWS::MSK::Cluster'
Properties:
BrokerNodeGroupInfo:
ClientSubnets:
- !Ref PrivateSubnetOne
- !Ref PrivateSubnetTwo
- !Ref PrivateSubnetThree
InstanceType: kafka.t3.small
SecurityGroups:
- !GetAtt
- MSKSecurityGroup
- GroupId
StorageInfo:
EBSStorageInfo:
VolumeSize: 10
ClusterName: MSKCluster
EncryptionInfo:
EncryptionInTransit:
ClientBroker: TLS
InCluster: true
EnhancedMonitoring: PER_TOPIC_PER_BROKER
KafkaVersion: 2.2.1
NumberOfBrokerNodes: 3
Outputs:
VPCId:
Description: The ID of the VPC created
Value: !Ref VPC
PublicSubnetOne:
Description: The name of the public subnet created
Value: !Ref PublicSubnetOne
PrivateSubnetOne:
Description: The ID of private subnet one created
Value: !Ref PrivateSubnetOne
PrivateSubnetTwo:
Description: The ID of private subnet two created
Value: !Ref PrivateSubnetTwo
PrivateSubnetThree:
Description: The ID of private subnet three created
Value: !Ref PrivateSubnetThree
MSKSecurityGroupID:
Description: The ID of the security group created for the MSK clusters
Value: !GetAtt
- MSKSecurityGroup
- GroupId
KafkaClientEC2InstancePublicDNS:
Description: The Public DNS for the MirrorMaker EC2 instance
Value: !GetAtt
- KafkaClientEC2Instance
- PublicDnsName
MSKClusterArn:
Description: The Arn for the MSKMMCluster1 MSK cluster
Value: !Ref MSKCluster