-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhirlpool-cf-template.yml
812 lines (740 loc) · 24.4 KB
/
whirlpool-cf-template.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
#
# Copyright (C) Rihan Pereira <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#
AWSTemplateFormatVersion: "2010-09-09"
# ----------- define basic/AWS specific parameters for whirlpool stack ---------
Parameters:
InstanceTypeParameters:
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- t2.small
Description: "choose among two choices available"
WhirlpoolVPCId:
Type: "AWS::EC2::VPC::Id"
Default: vpc-0c7a0ba5e8cad5b83
Description: "existing vpc id of whirlpool"
RDSMasterUsernameParam:
Type: String
Default: postgres
Description: "RDS master username"
RDSMasterPWDParam:
Type: String
Description: "RDS master password"
RDSWhirlpoolUserParam:
Type: String
Description: "RDS whirlpool user name"
RDSWhirlpoolPWDParam:
Type: String
Description: "RDS whirlpool pwd"
RDSDBNameParam:
Type: String
Description: "postgres db name to initiate"
RDSEndpoint:
Type: String
Description: "postgres connection endpoint used by crawler nodes"
SSHKeyPair:
Type: "AWS::EC2::KeyPair::KeyName"
Default: whirlpool-jumbox
Description: "Amazon ec2 key pair to use"
UbuntuImageId:
Type: "AWS::EC2::Image::Id"
Default: ami-05c1fa8df71875112
Description: "image id for ubuntu images"
NATImageId:
Type: "AWS::EC2::Image::Id"
Default: ami-00d1f8201864cc10c
Description: "image id of NAT instance"
# ---------- defines AWS resources for whirlpool project ---------------
Resources:
# define internet gateway to attach to already existing VPC
whirlpoolIGW:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: whirlpool-igw
# vpc internet gateway attachment resource
WhirlpoolGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId:
Ref: WhirlpoolVPCId
InternetGatewayId:
Ref: whirlpoolIGW
# ------------- define 4 subnets within an existing VPC ----------------------
whirlpoolPublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: "vpc-0c7a0ba5e8cad5b83"
CidrBlock: "10.0.0.0/28"
AvailabilityZone: "us-east-2a"
Tags:
- Key: Name
Value: whirlpool-public-sub-1
whirlpoolPrivateSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: "vpc-0c7a0ba5e8cad5b83"
CidrBlock: "10.0.0.16/28"
AvailabilityZone: "us-east-2a"
Tags:
- Key: Name
Value: whirlpool-private-sub-2
whirlpoolPrivateSubnet3:
Type: AWS::EC2::Subnet
Properties:
VpcId: "vpc-0c7a0ba5e8cad5b83"
CidrBlock: "10.0.0.32/28"
AvailabilityZone: "us-east-2b"
Tags:
- Key: Name
Value: whirlpool-private-sub-3
whirlpoolPrivateSubnet4:
Type: AWS::EC2::Subnet
Properties:
VpcId: "vpc-0c7a0ba5e8cad5b83"
CidrBlock: "10.0.0.48/28"
AvailabilityZone: "us-east-2a"
Tags:
- Key: Name
Value: whirlpool-private-sub-4
# ------------define all security groups for whirlpool project----------------------
# ------------ whirlpool crawler sec grp for pvt sub 4 ----------------------
whirlpoolCrawlerSecGrpPvtSub4:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "outbounds internets, inbounds ssh only from bastion instance"
GroupName: "whirlpool-crawler-secgrp-pvtsub-4"
VpcId: "vpc-0c7a0ba5e8cad5b83"
Tags:
- Key: Name
Value: whirlpool-crawler-secgrp-pvtsub-4
SSHFromBastionInboundRulePvtSub4:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 22
ToPort: 22
Description: "only allow ssh to crawler nodes from bastion instance"
GroupId:
Fn::GetAtt:
- whirlpoolCrawlerSecGrpPvtSub4
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
TunnelRMQtrafficInboundRulePvtSub4:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 8080
ToPort: 8080
Description: "access rmq mangement console traffic from bastion node tunneled to client host"
GroupId:
Fn::GetAtt:
- whirlpoolCrawlerSecGrpPvtSub4
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
TunnelPGAdmintrafficInboundRulePvtSub4:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 8083
ToPort: 8083
Description: "accept pgadmin traffic from bastion node tunneled to client host"
GroupId:
Fn::GetAtt:
- whirlpoolCrawlerSecGrpPvtSub4
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
OutBoundRulePvtSub4:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
GroupId:
Fn::GetAtt:
- whirlpoolCrawlerSecGrpPvtSub4
- GroupId
# ------------ whirlpool mongo sec grp pvt sub 2 ----------------------
whirlpoolMongoSecGrpPvtSub2:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "accept incoming mongo traffic on 27017 from crawlers, ssh from bastion"
GroupName: "whirlpool-mongodb-secgrp-pvtsub-2"
VpcId: "vpc-0c7a0ba5e8cad5b83"
Tags:
- Key: Name
Value: whirlpool-mongodb-secgrp-pvtsub-2
SSHFromBastionInboundRulePvtSub2:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 22
ToPort: 22
Description: "ssh only from bastion instance"
GroupId:
Fn::GetAtt:
- whirlpoolMongoSecGrpPvtSub2
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
MongoTrafficInboundRulePvtSub2:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 27017
ToPort: 27017
Description: "mongo traffic from crawler nodes"
GroupId:
Fn::GetAtt:
- whirlpoolMongoSecGrpPvtSub2
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolCrawlerSecGrpPvtSub4
- GroupId
TunnelEgressMongoInboundRulePvtSub2:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 27017
ToPort: 27017
Description: "egress mongo traffic tunneled to client host"
GroupId:
Fn::GetAtt:
- whirlpoolMongoSecGrpPvtSub2
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
OutBoundRulePvtSub2:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
GroupId:
Fn::GetAtt:
- whirlpoolMongoSecGrpPvtSub2
- GroupId
# ------------ whirlpool bastion sec grp for pub sub 1 ------------------
whirlpoolBastionNatSecGrpPubSub1:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "whirlpool bastion node in public subnet 1"
GroupName: "whirlpool-bastion-nat-sec-grp-pubsub-1"
VpcId: "vpc-0c7a0ba5e8cad5b83"
Tags:
- Key: Name
Value: whirlpool-bastion-nat-sec-grp-pubsub-1
SSHInboundRulePubSub1:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
Description: "only from my workstation"
GroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
CrawlerNonSSLHttpInboundRulePubSub1:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 80
ToPort: 80
Description: "crawler downloads non-ssl http traffic"
GroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolCrawlerSecGrpPvtSub4
- GroupId
CrawlerSSLHttpInboundRulePubSub1:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 443
ToPort: 443
Description: "crawler downloads ssl http traffic"
GroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolCrawlerSecGrpPvtSub4
- GroupId
PullDockerMongoNonSSLHttpInboundRulePubSub1:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 80
ToPort: 80
Description: "pull mongo docker container, ubuntu updates without ssl"
GroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolMongoSecGrpPvtSub2
- GroupId
PullDockerMongoSSLHttpInboundRulePubSub1:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 443
ToPort: 443
Description: "pull mongo docker container, ubuntu updates with ssl"
GroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolMongoSecGrpPvtSub2
- GroupId
OutBoundRulePubSub1:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
GroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
# -------------whirlpool rds sec grp pvt sub 2 and 3 ----------------
whirlpoolRDSSecGrpPvtSub23:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "accept inbound postgres 5432 from crawler nodes only"
GroupName: "whirlpool-rds-secgrp-pvtsub-2-3"
VpcId: "vpc-0c7a0ba5e8cad5b83"
Tags:
- Key: Name
Value: whirlpool-rds-secgrp-pvtsub-2-3
RDSTrafficToCrawlerInboundRulePvtSub23:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 5432
ToPort: 5432
Description: "accept sql request from crawlers"
GroupId:
Fn::GetAtt:
- whirlpoolRDSSecGrpPvtSub23
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolCrawlerSecGrpPvtSub4
- GroupId
RDSTrafficToBastionInboundRulePvtSub23:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 5432
ToPort: 5432
Description: "egress rds tunneled to client host"
GroupId:
Fn::GetAtt:
- whirlpoolRDSSecGrpPvtSub23
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
OutBoundRulePvtSub23:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
GroupId:
Fn::GetAtt:
- whirlpoolRDSSecGrpPvtSub23
- GroupId
# ----------------whirlpool memcache sec grp pvt sub 2 -------------------
whirlpoolMemcacheSecGrpPvtSub2:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: "accept memcache traffic from crawlers only"
GroupName: "whirlpool-memcache-secgrp-pvtsub-2"
VpcId: "vpc-0c7a0ba5e8cad5b83"
Tags:
- Key: Name
Value: whirlpool-memcache-secgrp-pvtsub-2
MemcacheTrafficToCrawlerInboundRulePvtSub2:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 11211
ToPort: 11211
Description: "allow memcache traffic from crawler nodes"
GroupId:
Fn::GetAtt:
- whirlpoolMemcacheSecGrpPvtSub2
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolCrawlerSecGrpPvtSub4
- GroupId
MemcacheTrafficToBastionInboundRulePvtSub2:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 11211
ToPort: 11211
Description: "egress cache traffic tunneled to client host"
GroupId:
Fn::GetAtt:
- whirlpoolMemcacheSecGrpPvtSub2
- GroupId
SourceSecurityGroupId:
Fn::GetAtt:
- whirlpoolBastionNatSecGrpPubSub1
- GroupId
OutBoundRulePvtSub2:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
GroupId:
Fn::GetAtt:
- whirlpoolMemcacheSecGrpPvtSub2
- GroupId
# ----- define RDS postgres instance -------------------
# 1. define RDS DB Subnet Group
RDSDBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: "subnet group for rds postgres instance"
DBSubnetGroupName: "whirlpool-postgres-rds-subgrp"
SubnetIds:
- !Ref whirlpoolPrivateSubnet2
- !Ref whirlpoolPrivateSubnet3
Tags:
-
Key: "Name"
Value: "whirlpool-postgres-rds-subgrp"
WhirlpoolPostgresProd:
Type: AWS::RDS::DBInstance
Properties:
AllocatedStorage: "20"
AutoMinorVersionUpgrade: true
AvailabilityZone: "us-east-2a"
BackupRetentionPeriod: 5
CopyTagsToSnapshot: true
DBInstanceClass: "db.t2.micro"
DBInstanceIdentifier: "whirlpool-postgres-prod"
DBSubnetGroupName: !Ref RDSDBSubnetGroup
DeleteAutomatedBackups: true
DeletionProtection: false
EnablePerformanceInsights: true
Engine: "postgres"
EngineVersion: "11.4"
MasterUsername: !Ref RDSMasterUsernameParam
MasterUserPassword: !Ref RDSMasterPWDParam
DBName: !Ref RDSDBNameParam
MultiAZ: false
PerformanceInsightsRetentionPeriod: 7
Port: "5432"
PubliclyAccessible: false
StorageType: "gp2"
Tags:
-
Key: Name
Value: "whirlpool postgres RDS instance used by contentseen and due"
UseDefaultProcessorFeatures: true
VPCSecurityGroups:
- !Ref whirlpoolRDSSecGrpPvtSub23
# -----------define whirlpool memcache ---------------
WhirlpoolMemCacheSubgrp:
Type: AWS::ElastiCache::SubnetGroup
Properties:
Description: "memcache subnet group for whirlpool memcache instance"
CacheSubnetGroupName: "whirlpool-memcache-subgrp"
SubnetIds:
- !Ref whirlpoolPrivateSubnet2
WhirlpoolCache:
Type: AWS::ElastiCache::CacheCluster
Properties:
AZMode: "single-az"
CacheNodeType: "cache.t2.micro"
CacheSubnetGroupName: !Ref WhirlpoolMemCacheSubgrp
ClusterName: "whirlpool-cache"
Engine: "memcached"
EngineVersion: "1.5.10"
NumCacheNodes: 1
Port: 11211
PreferredAvailabilityZone: "us-east-2a"
Tags:
-
Key: Name
Value: "whirlpool-cache"
VpcSecurityGroupIds:
- !GetAtt whirlpoolMemcacheSecGrpPvtSub2.GroupId
# ----------- define mongodb ec2 instance in pvt sub 2 -------------
whirlpoolMongo:
Type: "AWS::EC2::Instance"
Properties:
AvailabilityZone: "us-east-2a"
BlockDeviceMappings:
- DeviceName: "/dev/sda1"
Ebs:
VolumeType: "gp2"
DeleteOnTermination: "true"
VolumeSize: "15"
NoDevice: {}
ImageId: !Ref UbuntuImageId
InstanceInitiatedShutdownBehavior: "stop"
InstanceType: !Ref InstanceTypeParameters
KeyName: !Ref SSHKeyPair
Monitoring: false
PrivateIpAddress: "10.0.0.26"
SecurityGroupIds:
- !GetAtt whirlpoolMongoSecGrpPvtSub2.GroupId
SourceDestCheck: true
SubnetId: !Ref whirlpoolPrivateSubnet2
Tags:
- Key: Name
Value: whirlpool-mongodb
- Key: Capacity
Value: 15GiB
- Key: ec2-purpose
Value: mongodb storage
- Key: placement
Value: pvtsub2
Tenancy: "default"
UserData: !Base64 |
#cloud-config
repo_update: true
packages:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
runcmd:
- [ sh, -c, "export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1"]
- [ sh, -c, 'curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add -' ]
- [ sh, -c, "apt-key fingerprint F273FCD8" ]
- [sh, -c, 'add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"' ]
- [ apt-get, update ]
- [ apt-get, install, -y, docker-ce ]
- [ sh, -c, "groupadd docker" ]
- [ sh, -c, "usermod -aG docker ubuntu" ]
- systemctl enable docker
- [ docker, volume, create, whirlpool-mongodbdata ]
- [ sh, -c, 'docker run --name whirlpool-mongodb -v "whirlpool-mongodbdata:/data/db" -p "27017:27017" -td "rihbyne/whirlpool-mongodb:latest"' ]
output: {all: '| tee -a /var/log/cloud-init-output.log'}
# ---------- define bastion NAT instance ------------------
whirlpoolBastionNode:
Type: "AWS::EC2::Instance"
DependsOn: WhirlpoolGatewayAttachment
Properties:
AvailabilityZone: "us-east-2a"
BlockDeviceMappings:
- DeviceName: "/dev/xvda"
Ebs:
VolumeType: "standard"
DeleteOnTermination: "false"
VolumeSize: "8"
# NoDevice: {}
ImageId: !Ref NATImageId
InstanceInitiatedShutdownBehavior: "stop"
InstanceType: !Ref InstanceTypeParameters
KeyName: !Ref SSHKeyPair
Monitoring: false
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
DeleteOnTermination: "true"
GroupSet:
- !GetAtt whirlpoolBastionNatSecGrpPubSub1.GroupId
SubnetId: !Ref whirlpoolPublicSubnet1
SourceDestCheck: false
Tags:
- Key: Name
Value: whirlpool-bastion-node
- Key: Capacity
Value: 8GiB
- Key: ec2-purpose
Value: bastion-node
- Key: placement
Value: pubsub-1
Tenancy: "default"
# UserData: String; come back later
# --------- define crawler node 1 ------------
whirlpoolCrawlerNode:
Type: "AWS::EC2::Instance"
Properties:
AvailabilityZone: "us-east-2a"
BlockDeviceMappings:
- DeviceName: "/dev/sda1"
Ebs:
VolumeType: "gp2"
DeleteOnTermination: "true"
VolumeSize: "8"
NoDevice: {}
ImageId: !Ref UbuntuImageId
InstanceInitiatedShutdownBehavior: "stop"
InstanceType: !Ref InstanceTypeParameters
KeyName: !Ref SSHKeyPair
Monitoring: false
PrivateIpAddress: "10.0.0.56"
SecurityGroupIds:
- !GetAtt whirlpoolCrawlerSecGrpPvtSub4.GroupId
SourceDestCheck: true
SubnetId: !Ref whirlpoolPrivateSubnet4
Tags:
- Key: Name
Value: whirlpool-crawler-node
- Key: Capacity
Value: 8GiB
- Key: ec2-purpose
Value: mercator crawler
- Key: placement
Value: pvtsub4
Tenancy: "default"
UserData:
Fn::Base64:
!Sub |
#cloud-config
repo_update: true
packages:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- gnupg
- netcat
runcmd:
- [ sh, -c, "export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1"]
- [ sh, -c, 'curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add -' ]
- [ sh, -c, "apt-key fingerprint F273FCD8" ]
- [ sh, -c, 'add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"' ]
- [ apt-get, update ]
- [ apt-get, install, -y, docker-ce ]
- [ sh, -c, "groupadd docker" ]
- [ sh, -c, "usermod -aG docker ubuntu" ]
- systemctl enable docker
- [ docker, network, create, whirlpool-net ]
- [ sh, -c, 'curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o "/usr/local/bin/docker-compose"' ]
- [ chmod, +x, "/usr/local/bin/docker-compose" ]
- [ sh, -c, 'curl "https://www.postgresql.org/media/keys/ACCC4CF8.asc" | apt-key add -' ]
- [ sh, -c, 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' ]
- [ apt-get, update ]
- [ apt-get, install, -y, --no-install-recommends, postgresql-client-11 ]
- [ rm, -rf, "/var/lib/apt/lists/*" ]
- [ sh, -c, "cd /root; touch .pgpass" ]
- pwd
- [ sh, -c, "chmod 0600 /root/.pgpass" ]
- [ sh, -c, 'echo "${RDSEndpoint}:5432:*:${RDSMasterUsernameParam}:${RDSMasterPWDParam}" > /root/.pgpass' ]
- [ sh, -c, 'export PGPASSFILE="/root/.pgpass"']
- [ sh, -c, 'while !(nc -z ${RDSEndpoint} 5432); do echo "sleeping"; sleep 3; done']
- [ psql, -h, "${RDSEndpoint}", -U, "${RDSMasterUsernameParam}", -c, "CREATE USER ${RDSWhirlpoolUserParam} WITH PASSWORD '${RDSWhirlpoolPWDParam}'" ]
- [ psql, -h, "${RDSEndpoint}", -U, "${RDSMasterUsernameParam}", -c, "GRANT ALL PRIVILEGES ON DATABASE ${RDSDBNameParam} TO ${RDSWhirlpoolUserParam}" ]
output: {all: '| tee -a /var/log/cloud-init-output.log'}
# --------- declare crawler node 2 later -----------------------
# -------------- define route table if everything above goes well -----------
# ------------- bastion route table on public subnet 1 ---------------
WhirlpoolBastionRTonPubSub1:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: WhirlpoolVPCId
Tags:
- Key: Name
Value: whirlpool-bastion-routetable-on-pubsub-1
WhirlpoolBastionRoutePubSub1:
Type: AWS::EC2::Route
DependsOn:
- whirlpoolIGW
- WhirlpoolGatewayAttachment
Properties:
RouteTableId: !Ref WhirlpoolBastionRTonPubSub1
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref whirlpoolIGW
WhirlpoolBastionSubnetRTAssociationPubSub1:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref whirlpoolPublicSubnet1
RouteTableId: !Ref WhirlpoolBastionRTonPubSub1
# ---------------- mongodb route table on pvt subnet 2 --------------
WhirlpoolMongoRTonPvtSub2:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref WhirlpoolVPCId
Tags:
- Key: Name
Value: whirlpool-mongodb-routetable-on-pvtsub-2
WhirlpoolMongoRoutePvtSub2:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref WhirlpoolMongoRTonPvtSub2
DestinationCidrBlock: 0.0.0.0/0
InstanceId: !Ref whirlpoolBastionNode
WhirlpoolMongoSubnetRTAssociationPvtSub2:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref whirlpoolPrivateSubnet2
RouteTableId: !Ref WhirlpoolMongoRTonPvtSub2
# ------------- crawler route tbale on pvt sub 4 ---------------
WhirlpoolCrawlerRTonPvtSub4:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref WhirlpoolVPCId
Tags:
- Key: Name
Value: whirlpool-crawler-route-table-on-pvtsub-4
WhirlpoolCrawlerRoutePvtSub4:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref WhirlpoolCrawlerRTonPvtSub4
DestinationCidrBlock: 0.0.0.0/0
InstanceId: !Ref whirlpoolBastionNode
WhirlpoolCrawlerSubnetRTAssociationPvtSub4:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref whirlpoolPrivateSubnet4
RouteTableId: !Ref WhirlpoolCrawlerRTonPvtSub4