-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloudformation.yaml
1428 lines (1273 loc) · 53.1 KB
/
cloudformation.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
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
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
AWSTemplateFormatVersion: 2010-09-09
# File format follows https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html
# Tests:
# Lint: https://github.com/aws-cloudformation/cfn-lint
# Nag: https://github.com/stelligent/cfn_nag
# aws cloudformation validate-template: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/validate-template.html
Description: >-
Senzing aws-cloudformation-database-cluster: 1.3.10
For more information see https://github.com/senzing-garage/aws-cloudformation-database-cluster
# -----------------------------------------------------------------------------
# Metadata
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html
# -----------------------------------------------------------------------------
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Senzing installation
Parameters:
- MultipleDatabases
- Label:
default: Security responsibility
Parameters:
- SecurityResponsibility
ParameterLabels:
MultipleDatabases:
default: 'Optional: Would you like to install into a single or multiple databases?'
SecurityResponsibility:
default: >-
Required: A default deployment of this template is for public demonstration only.
Before using authentic PII, ensure the security of your deployment.
The security of this deployment is your responsibility.
To acknowledge your understanding and acceptance of the foregoing, type “I AGREE”.
# -----------------------------------------------------------------------------
# Parameters
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
# -----------------------------------------------------------------------------
Parameters:
# AWS Console: https://console.aws.amazon.com/cloudformation/home?#/stacks > {stack} > Parameters
MultipleDatabases:
AllowedValues:
- 'Single'
- 'Multiple'
Default: 'Single'
Description: 'Help: https://hub.senzing.com/aws-cloudformation-database-cluster/#multipledatabases'
Type: String
SecurityResponsibility:
AllowedPattern: '.+|^I AGREE$'
ConstraintDescription: SecurityResponsibility parameter must be 'I AGREE'
Default: '_'
Description: 'Help: https://hub.senzing.com/aws-cloudformation-database-cluster/#securityresponsibility'
Type: String
# -----------------------------------------------------------------------------
# Rules
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/rules-section-structure.html
# -----------------------------------------------------------------------------
Rules:
ConfirmSecurityResponsibility:
Assertions:
- Assert: !Equals
- !Ref SecurityResponsibility
- 'I AGREE'
AssertDescription: 'Understanding responsibility and entering "I AGREE" is required to proceed.'
# -----------------------------------------------------------------------------
# Mappings
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html
# -----------------------------------------------------------------------------
Mappings:
Constants:
Database:
Name: G2
Username: senzing
Images:
InitPostgresql: public.ecr.aws/senzing/init-database:0.5.2
Stack:
Name: database-cluster
VpcCidrs:
vpc:
cidr: 10.0.0.0/16
privsubnet1:
cidr: 10.0.10.0/22
privsubnet2:
cidr: 10.0.20.0/22
pubsubnet1:
cidr: 10.0.30.0/22
pubsubnet2:
cidr: 10.0.40.0/22
# -----------------------------------------------------------------------------
# Conditions
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html
# -----------------------------------------------------------------------------
Conditions:
IfMultipleDatabases: !Equals
- !Ref MultipleDatabases
- 'Multiple'
IfSingleDatabase: !Not
- !Equals [!Ref MultipleDatabases, 'Multiple']
# -----------------------------------------------------------------------------
# Resources
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html
# -----------------------------------------------------------------------------
Resources:
# -- Iam -----------------------------------------------------------------
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html
# AWS Console: https://console.aws.amazon.com/iam/home?#/roles > Search for {stack}
IamRoleInitPostgres:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
Version: '2012-10-17'
Description: !Sub '${AWS::StackName}-iam-role-init-postgres'
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-iam-role-init-postgres'
Type: AWS::IAM::Role
IamRoleLambda:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
- lambda.amazonaws.com
- route53.amazonaws.com
- sqs.amazonaws.com
Version: '2012-10-17'
Description: !Sub '${AWS::StackName}-iam-role-lambda'
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-iam-role-lambda'
Type: AWS::IAM::Role
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-policy.html
# AWS Console: https://console.aws.amazon.com/iam/home?#/roles > Search for {stack} > {role} > inline policy
IamPolicyLoggingCreateStream:
Properties:
PolicyName: !Sub '${AWS::StackName}-iam-policy-logging-create-stream'
PolicyDocument:
Statement:
- Action:
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource:
- '*'
Version: '2012-10-17'
Roles:
- !Ref IamRoleInitPostgres
- !Ref IamRoleLambda
Type: AWS::IAM::Policy
IamPolicyPassRole:
Properties:
PolicyName: !Sub '${AWS::StackName}-iam-policy-pass-role'
PolicyDocument:
Statement:
- Action:
- iam:PassRole
Effect: Allow
Resource:
- '*'
Version: '2012-10-17'
Roles:
- !Ref IamRoleLambda
Type: AWS::IAM::Policy
IamPolicyRds:
Properties:
PolicyName: !Sub '${AWS::StackName}-iam-policy-rds'
PolicyDocument:
Statement:
- Action:
- rds:ModifyDBCluster
Effect: Allow
Resource:
- '*'
Version: '2012-10-17'
Roles:
- !Ref IamRoleLambda
Type: AWS::IAM::Policy
IamPolicyTaskRunner:
Properties:
PolicyName: !Sub '${AWS::StackName}-iam-policy-task-runner'
PolicyDocument:
Statement:
- Action:
- ecs:DescribeTasks
- ecs:RunTask
- ecs:TagResource
Effect: Allow
Resource:
- '*'
Version: '2012-10-17'
Roles:
- !Ref IamRoleLambda
Type: AWS::IAM::Policy
# -- Logging ------------------------------------------------------------------
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html
# AWS Console: https://console.aws.amazon.com/cloudwatch/home?#logsV2:log-groups > Search for {stack}
LogsLogGroupDbCluster:
Condition: IfSingleDatabase
Properties:
LogGroupName: !Sub
- '/aws/rds/cluster/${StackNameAsLower}-aurora-senzing-cluster/postgresql'
- StackNameAsLower: !GetAtt LambdaRunnerStackNameAsLower.OutputString
Type: AWS::Logs::LogGroup
LogsLogGroupDbClusterCore:
Condition: IfMultipleDatabases
Properties:
LogGroupName: !Sub
- '/aws/rds/cluster/${StackNameAsLower}-aurora-senzing-core-cluster/postgresql'
- StackNameAsLower: !GetAtt LambdaRunnerStackNameAsLower.OutputString
Type: AWS::Logs::LogGroup
LogsLogGroupDbClusterLibfeat:
Condition: IfMultipleDatabases
Properties:
LogGroupName: !Sub
- '/aws/rds/cluster/${StackNameAsLower}-aurora-senzing-libfeat-cluster/postgresql'
- StackNameAsLower: !GetAtt LambdaRunnerStackNameAsLower.OutputString
Type: AWS::Logs::LogGroup
LogsLogGroupDbClusterRes:
Condition: IfMultipleDatabases
Properties:
LogGroupName: !Sub
- '/aws/rds/cluster/${StackNameAsLower}-aurora-senzing-res-cluster/postgresql'
- StackNameAsLower: !GetAtt LambdaRunnerStackNameAsLower.OutputString
Type: AWS::Logs::LogGroup
LogsLogGroupLambdaRandomPassword:
Properties:
LogGroupName: !Sub '/aws/lambda/${AWS::StackName}-lambda-random-password'
Type: AWS::Logs::LogGroup
LogsLogGroupLambdaRandomString:
Properties:
LogGroupName: !Sub '/aws/lambda/${AWS::StackName}-lambda-random-string'
Type: AWS::Logs::LogGroup
LogsLogGroupLambdaRunTask:
Properties:
LogGroupName: !Sub '/aws/lambda/${AWS::StackName}-lambda-run-task'
Type: AWS::Logs::LogGroup
LogsLogGroupLambdaRunTaskAndWait:
Properties:
LogGroupName: !Sub '/aws/lambda/${AWS::StackName}-lambda-run-task-and-wait'
Type: AWS::Logs::LogGroup
LogsLogGroupLambdaSetRdbTimeoutAction:
Properties:
LogGroupName: !Sub '/aws/lambda/${AWS::StackName}-lambda-set-rdb-timeout-action'
Type: AWS::Logs::LogGroup
LogsLogGroupLambdaStringToLower:
Properties:
LogGroupName: !Sub '/aws/lambda/${AWS::StackName}-lambda-string-to-lower'
Type: AWS::Logs::LogGroup
LogsLogGroupMain:
Properties:
LogGroupName: !Sub
- '/senzing/${StackName}/${AWS::StackName}'
- StackName: !FindInMap [Constants, Stack, Name]
Type: AWS::Logs::LogGroup
# -- Cloud, subnets, routing --------------------------------------------------
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#vpcs > Search for {stack}
Ec2Vpc:
Properties:
CidrBlock: !FindInMap
- VpcCidrs
- vpc
- cidr
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-vpc'
Type: AWS::EC2::VPC
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#subnets > Search for {stack}
Ec2SubnetPrivate1:
Properties:
AvailabilityZone: !Select
- '0'
- !GetAZs
Ref: AWS::Region
CidrBlock: !FindInMap
- VpcCidrs
- privsubnet1
- cidr
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-subnet-private-1'
VpcId: !Ref Ec2Vpc
Type: AWS::EC2::Subnet
Ec2SubnetPrivate2:
Properties:
AvailabilityZone: !Select
- '1'
- !GetAZs
Ref: AWS::Region
CidrBlock: !FindInMap
- VpcCidrs
- privsubnet2
- cidr
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-subnet-private-2'
VpcId: !Ref Ec2Vpc
Type: AWS::EC2::Subnet
Ec2SubnetPublic1:
Properties:
AvailabilityZone: !Select
- '0'
- !GetAZs
Ref: AWS::Region
CidrBlock: !FindInMap
- VpcCidrs
- pubsubnet1
- cidr
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-subnet-public-1'
VpcId: !Ref Ec2Vpc
Type: AWS::EC2::Subnet
Ec2SubnetPublic2:
Properties:
AvailabilityZone: !Select
- '1'
- !GetAZs
Ref: AWS::Region
CidrBlock: !FindInMap
- VpcCidrs
- pubsubnet2
- cidr
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-subnet-public-2'
VpcId: !Ref Ec2Vpc
Type: AWS::EC2::Subnet
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-eip.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#Addresses: > Search for {stack}
Ec2Eip:
Properties:
Domain: vpc
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-eip'
Type: AWS::EC2::EIP
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-natgateway.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#NatGateways: > Search for {stack}
Ec2NatGateway:
Properties:
AllocationId: !GetAtt Ec2Eip.AllocationId
SubnetId: !Ref Ec2SubnetPublic1
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-nat-gateway'
Type: AWS::EC2::NatGateway
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#SecurityGroups > Search for {stack}
Ec2SecurityGroupInternal:
Properties:
GroupDescription: !Sub '${AWS::StackName} - ECS internal open ports.'
SecurityGroupEgress:
- CidrIp: 0.0.0.0/0
Description: All
IpProtocol: '-1'
SecurityGroupIngress:
- CidrIp: !FindInMap
- VpcCidrs
- vpc
- cidr
Description: PostgreSQL
FromPort: 5432
IpProtocol: tcp
ToPort: 5432
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-security-group-internal'
VpcId: !Ref Ec2Vpc
Type: AWS::EC2::SecurityGroup
Ec2SecurityGroupLambdaRunner:
Properties:
GroupDescription: !Sub '${AWS::StackName} - Lambda open ports.'
SecurityGroupEgress:
- CidrIp: 0.0.0.0/0
Description: All
IpProtocol: '-1'
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-security-group-lambda-runner'
VpcId: !Ref Ec2Vpc
Type: AWS::EC2::SecurityGroup
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-internetgateway.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#igws > Search for {stack}
Ec2InternetGateway:
Properties:
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-internet-gateway'
Type: AWS::EC2::InternetGateway
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc-gateway-attachment.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#igws > Search for {stack} > State & VPI ID
Ec2VpcGatewayAttachment:
Properties:
InternetGatewayId: !Ref Ec2InternetGateway
VpcId: !Ref Ec2Vpc
Type: AWS::EC2::VPCGatewayAttachment
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-route-table.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#RouteTables > Search for {stack}
Ec2RouteTablePrivate:
Properties:
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-route-table-private'
VpcId: !Ref Ec2Vpc
Type: AWS::EC2::RouteTable
Ec2RouteTablePublic:
Properties:
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ec2-route-table-public'
VpcId: !Ref Ec2Vpc
Type: AWS::EC2::RouteTable
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-route.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#RouteTables > {name} > "Routes" tab
Ec2RoutePrivate:
Properties:
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref Ec2NatGateway
RouteTableId: !Ref Ec2RouteTablePrivate
Type: AWS::EC2::Route
Ec2RoutePublic:
DependsOn:
- Ec2VpcGatewayAttachment
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref Ec2InternetGateway
RouteTableId: !Ref Ec2RouteTablePublic
Type: AWS::EC2::Route
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet-route-table-assoc.html
# AWS Console: https://console.aws.amazon.com/vpc/home?#RouteTables > {name} > "Subnet Associations" tab
Ec2SubnetRouteTableAssociationPrivate1:
Properties:
RouteTableId: !Ref Ec2RouteTablePrivate
SubnetId: !Ref Ec2SubnetPrivate1
Type: AWS::EC2::SubnetRouteTableAssociation
Ec2SubnetRouteTableAssociationPrivate2:
Properties:
RouteTableId: !Ref Ec2RouteTablePrivate
SubnetId: !Ref Ec2SubnetPrivate2
Type: AWS::EC2::SubnetRouteTableAssociation
Ec2SubnetRouteTableAssociationPublic1:
Properties:
RouteTableId: !Ref Ec2RouteTablePublic
SubnetId: !Ref Ec2SubnetPublic1
Type: AWS::EC2::SubnetRouteTableAssociation
Ec2SubnetRouteTableAssociationPublic2:
Properties:
RouteTableId: !Ref Ec2RouteTablePublic
SubnetId: !Ref Ec2SubnetPublic2
Type: AWS::EC2::SubnetRouteTableAssociation
# -- Database -----------------------------------------------------------------
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbsubnet-group.html
# AWS Console: https://console.aws.amazon.com/rds/home#db-subnet-groups-list: > Search for {stack}
RdsDbSubnetGroup:
Properties:
DBSubnetGroupDescription: !Sub '${AWS::StackName}-db-subnet-description'
DBSubnetGroupName: !Sub '${AWS::StackName}-db-subnet'
SubnetIds:
- !Ref Ec2SubnetPrivate1
- !Ref Ec2SubnetPrivate2
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-rds-db-subnet-group'
Type: AWS::RDS::DBSubnetGroup
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbclusterparametergroup.html
# AWS Console: https://console.aws.amazon.com/rds/home?#parameter-groups: > Search for {stack}
RdsDbClusterParameterGroup:
Properties:
Description: !Sub '${AWS::StackName}-rds-db-cluster-parameter-group-description'
Family: aurora-postgresql13
Parameters:
autovacuum_max_workers: 5
enable_seqscan: 0
pglogical.synchronous_commit: 0
synchronous_commit: 'off'
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-rds-db-cluster-parameter-group'
Type: AWS::RDS::DBClusterParameterGroup
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html
# AWS Console: https://console.aws.amazon.com/rds/home?#databases: > Search for {stack}
RdsDbCluster:
Condition: IfSingleDatabase
DependsOn:
- LogsLogGroupDbCluster
- RdsDbSubnetGroup
Properties:
AvailabilityZones:
- !GetAtt Ec2SubnetPrivate1.AvailabilityZone
- !GetAtt Ec2SubnetPrivate2.AvailabilityZone
DatabaseName: G2
DBClusterIdentifier: !Sub '${AWS::StackName}-aurora-senzing-cluster'
DBClusterParameterGroupName:
Ref: RdsDbClusterParameterGroup
# FIXME: Tricky code. See https://console.aws.amazon.com/support/home#/case/?displayId=7725760511
DBSubnetGroupName: !Sub
- '${StackNameAsLower}-db-subnet'
- StackNameAsLower: !GetAtt LambdaRunnerStackNameAsLower.OutputString
DeletionProtection: false
EnableHttpEndpoint: true
Engine: aurora-postgresql
EngineMode: serverless
EngineVersion: '13.12'
MasterUsername: !FindInMap [Constants, Database, Username]
MasterUserPassword: !GetAtt LambdaRunnerDbPassword.RandomString
ScalingConfiguration:
AutoPause: true
MaxCapacity: 192
MinCapacity: 2
SecondsUntilAutoPause: 3600
# FIXME: Uncomment once 'TimeoutAction' is supported.
# https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/298
# https://console.aws.amazon.com/support/home#/case/?displayId=7705681311&language=en
# TimeoutAction: ForceApplyCapacityChange
StorageEncrypted: true
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-rds-db-cluster'
VpcSecurityGroupIds:
- !Ref Ec2SecurityGroupInternal
Type: AWS::RDS::DBCluster
RdsDbClusterCore:
Condition: IfMultipleDatabases
DependsOn:
- LogsLogGroupDbClusterCore
- RdsDbSubnetGroup
Properties:
AvailabilityZones:
- !GetAtt Ec2SubnetPrivate1.AvailabilityZone
- !GetAtt Ec2SubnetPrivate2.AvailabilityZone
DatabaseName: G2
DBClusterIdentifier: !Sub '${AWS::StackName}-aurora-senzing-core-cluster'
DBClusterParameterGroupName:
Ref: RdsDbClusterParameterGroup
# FIXME: Tricky code. See https://console.aws.amazon.com/support/home#/case/?displayId=7725760511
DBSubnetGroupName: !Sub
- '${StackNameAsLower}-db-subnet'
- StackNameAsLower: !GetAtt LambdaRunnerStackNameAsLower.OutputString
DeletionProtection: false
EnableHttpEndpoint: true
Engine: aurora-postgresql
EngineMode: serverless
EngineVersion: '13.12'
MasterUsername: !FindInMap [Constants, Database, Username]
MasterUserPassword: !GetAtt LambdaRunnerDbPassword.RandomString
ScalingConfiguration:
AutoPause: true
MaxCapacity: 192
MinCapacity: 2
SecondsUntilAutoPause: 3600
# FIXME: Uncomment once 'TimeoutAction' is supported.
# https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/298
# https://console.aws.amazon.com/support/home#/case/?displayId=7705681311&language=en
# TimeoutAction: ForceApplyCapacityChange
StorageEncrypted: true
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-rds-db-core-cluster'
VpcSecurityGroupIds:
- !Ref Ec2SecurityGroupInternal
Type: AWS::RDS::DBCluster
RdsDbClusterLibfeat:
Condition: IfMultipleDatabases
DependsOn:
- LogsLogGroupDbClusterLibfeat
- RdsDbSubnetGroup
Properties:
AvailabilityZones:
- !GetAtt Ec2SubnetPrivate1.AvailabilityZone
- !GetAtt Ec2SubnetPrivate2.AvailabilityZone
DatabaseName: G2
DBClusterIdentifier: !Sub '${AWS::StackName}-aurora-senzing-libfeat-cluster'
DBClusterParameterGroupName:
Ref: RdsDbClusterParameterGroup
# FIXME: Tricky code. See https://console.aws.amazon.com/support/home#/case/?displayId=7725760511
DBSubnetGroupName: !Sub
- '${StackNameAsLower}-db-subnet'
- StackNameAsLower: !GetAtt LambdaRunnerStackNameAsLower.OutputString
DeletionProtection: false
EnableHttpEndpoint: true
Engine: aurora-postgresql
EngineMode: serverless
EngineVersion: '13.12'
MasterUsername: !FindInMap [Constants, Database, Username]
MasterUserPassword: !GetAtt LambdaRunnerDbPassword.RandomString
ScalingConfiguration:
AutoPause: true
MaxCapacity: 192
MinCapacity: 2
SecondsUntilAutoPause: 3600
# FIXME: Uncomment once 'TimeoutAction' is supported.
# https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/298
# https://console.aws.amazon.com/support/home#/case/?displayId=7705681311&language=en
# TimeoutAction: ForceApplyCapacityChange
StorageEncrypted: true
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-rds-db-libfeat-cluster'
VpcSecurityGroupIds:
- !Ref Ec2SecurityGroupInternal
Type: AWS::RDS::DBCluster
RdsDbClusterRes:
Condition: IfMultipleDatabases
DependsOn:
- LogsLogGroupDbClusterRes
- RdsDbSubnetGroup
Properties:
AvailabilityZones:
- !GetAtt Ec2SubnetPrivate1.AvailabilityZone
- !GetAtt Ec2SubnetPrivate2.AvailabilityZone
DatabaseName: G2
DBClusterIdentifier: !Sub '${AWS::StackName}-aurora-senzing-res-cluster'
DBClusterParameterGroupName:
Ref: RdsDbClusterParameterGroup
# FIXME: Tricky code. See https://console.aws.amazon.com/support/home#/case/?displayId=7725760511
DBSubnetGroupName: !Sub
- '${StackNameAsLower}-db-subnet'
- StackNameAsLower: !GetAtt LambdaRunnerStackNameAsLower.OutputString
DeletionProtection: false
EnableHttpEndpoint: true
Engine: aurora-postgresql
EngineMode: serverless
EngineVersion: '13.12'
MasterUsername: !FindInMap [Constants, Database, Username]
MasterUserPassword: !GetAtt LambdaRunnerDbPassword.RandomString
ScalingConfiguration:
AutoPause: true
MaxCapacity: 384
MinCapacity: 2
SecondsUntilAutoPause: 3600
# FIXME: Uncomment once 'TimeoutAction' is supported.
# https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/298
# https://console.aws.amazon.com/support/home#/case/?displayId=7705681311&language=en
# TimeoutAction: ForceApplyCapacityChange
StorageEncrypted: true
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-rds-db-res-cluster'
VpcSecurityGroupIds:
- !Ref Ec2SecurityGroupInternal
Type: AWS::RDS::DBCluster
# -- ECS Cluster --------------------------------------------------------------
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html
# AWS Console: https://console.aws.amazon.com/ecs/home?#/clusters > Search for {stack}
EcsCluster:
Properties:
ClusterName: !Sub '${AWS::StackName}-cluster'
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-ecs-cluster'
Type: AWS::ECS::Cluster
# -- Wait conditions ----------------------------------------------------------
DbClusterCoreReady:
Metadata:
DBClusterCoreReady: !If
- IfSingleDatabase
- !GetAtt RdsDbCluster.Endpoint.Address
- !GetAtt RdsDbClusterCore.Endpoint.Address
Type: AWS::CloudFormation::WaitConditionHandle
DbClusterLibfeatReady:
Metadata:
DBClusterCoreReady: !If
- IfSingleDatabase
- !GetAtt RdsDbCluster.Endpoint.Address
- !GetAtt RdsDbClusterLibfeat.Endpoint.Address
Type: AWS::CloudFormation::WaitConditionHandle
DbClusterResReady:
Metadata:
DBClusterCoreReady: !If
- IfSingleDatabase
- !GetAtt RdsDbCluster.Endpoint.Address
- !GetAtt RdsDbClusterRes.Endpoint.Address
Type: AWS::CloudFormation::WaitConditionHandle
# -- LambdaFunction -----------------------------------------------------------
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html
# AWS Console: https://console.aws.amazon.com/lambda/home?#/functions > Search for {stack}
LambdaFunctionRandomString:
DependsOn:
- Ec2SubnetRouteTableAssociationPrivate1
- Ec2SubnetRouteTableAssociationPrivate2
Properties:
Code:
ZipFile: |
#!/usr/bin/env python3
import cfnresponse
import json
import logging
import random
import string
import traceback
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def handler(event, context):
result = cfnresponse.SUCCESS
response_data = {}
try:
logger.info("Event: {0}".format(json.dumps(event)))
if event['RequestType'] in ['Create', 'Update']:
properties = event.get('ResourceProperties', {})
length = int(properties.get('Length', 0))
response_data["RandomString"] = ''.join(random.choices(string.ascii_letters + string.digits, k=length))
except Exception as e:
logger.error(e)
traceback.print_exc()
result = cfnresponse.FAILED
finally:
cfnresponse.send(event, context, result, response_data)
Description: Generate string of random characters.
FunctionName: !Sub '${AWS::StackName}-lambda-random-string'
Handler: index.handler
Role: !GetAtt IamRoleLambda.Arn
Runtime: python3.8
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-lambda-random-string'
Timeout: 600
Type: AWS::Lambda::Function
LambdaFunctionRunTaskAndWait:
DependsOn:
- Ec2SubnetRouteTableAssociationPrivate1
- Ec2SubnetRouteTableAssociationPrivate2
Properties:
Code:
ZipFile: |
#!/usr/bin/env python3
import boto3
import cfnresponse
import datetime
import json
import logging
import traceback
from json import JSONEncoder
logger = logging.getLogger()
logger.setLevel(logging.INFO)
class DateTimeEncoder(JSONEncoder):
def default(self, obj):
if isinstance(obj, (datetime.date, datetime.datetime)):
return obj.isoformat()
def handler(event, context):
result = cfnresponse.SUCCESS
response = {}
try:
logger.info("Event: {0}".format(json.dumps(event)))
if event['RequestType'] in ['Create', 'Update']:
properties = event.get('ResourceProperties', {})
run_task_parameters = properties.get('RunTaskParameters', {})
# Change strings to integers.
numbers = [
"count",
]
for number in numbers:
if number in run_task_parameters:
run_task_parameters[number] = int(run_task_parameters[number])
# Make AWS ECS request.
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.run_task
ecs = boto3.client('ecs')
response = ecs.run_task(**run_task_parameters)
# Wait for completion.
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#waiters
task_list = response.get('tasks', [])
if len(task_list) > 0:
taskArn = task_list[0].get('taskArn', None)
cluster = properties.get('ClusterId', None)
if not [x for x in (taskArn, cluster) if x is None]:
waiter = ecs.get_waiter('tasks_stopped')
waiter.wait(
cluster=cluster,
tasks=[taskArn],
)
response['describe_task'] = ecs.describe_tasks(
cluster=cluster,
tasks=[taskArn],
)
logger.info("describe_task response: {0}".format(json.dumps(response.get('describe_task', {}), cls=DateTimeEncoder)))
# test for failures and log any
fail_list = response.get('failures', [])
if len(fail_list) > 0:
for item in fail_list:
logger.info(f"Task failed to run. ARN: {item.get('arn', 'unknown')}")
logger.info(f" Reason: {item.get('reason', 'unknown')}")
logger.info(f" Details: {item.get('detail','none')}")
exit_code = response.get('describe_task', {}).get('tasks', [{}])[0].get('containers', [{}])[0].get('exitCode', 99)
if exit_code != 0:
result = cfnresponse.FAILED
logger.info("Response: {0}".format(json.dumps(response, cls=DateTimeEncoder)))
except Exception as e:
logger.error(e)
traceback.print_exc()
result = cfnresponse.FAILED
finally:
cfnresponse.send(event, context, result, {})
Description: Runs an ECS task and waits until completion.
FunctionName: !Sub '${AWS::StackName}-lambda-run-task-and-wait'
Handler: index.handler
Role: !GetAtt IamRoleLambda.Arn
Runtime: python3.8
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-lambda-run-task-and-wait'
Timeout: 600
Type: AWS::Lambda::Function
LambdaFunctionSenzingEngineConfigurationJson:
Properties:
Code:
ZipFile: |
#!/usr/bin/env python3
import cfnresponse
import json
import logging
import traceback
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def handler(event, context):
result = cfnresponse.SUCCESS
response_data = {}
try:
logger.info("Event: {0}".format(json.dumps(event)))
if event['RequestType'] in ['Create', 'Update']:
properties = event.get('ResourceProperties', {})
database_name = properties.get('DatabaseName', '')
database_user_name = properties.get('DatabaseUsername', '')
database_password = properties.get('DatabasePassword', '')
database_host_core = properties.get('DatabaseHostCore', '')
database_port_core = properties.get('DatabasePortCore', '')
database_host_res = properties.get('DatabaseHostRes', '')
database_port_res = properties.get('DatabasePortRes', '')
database_host_libfeat = properties.get('DatabaseHostLibfeat', '')
database_port_libfeat = properties.get('DatabasePortLibfeat', '')
db_config = 'Multiple'
if database_host_core == database_host_res == database_host_libfeat:
db_config = 'Single'
logger.info(f"db_config={db_config}")
license_string = properties.get('SenzingLicenseAsBase64', '')
if db_config == 'Single':
response_data["ConfigJSON"] = (
'{'
' "PIPELINE": {'
' "CONFIGPATH": "/etc/opt/senzing",'
f' "LICENSESTRINGBASE64": "{license_string}",'
' "RESOURCEPATH": "/opt/senzing/g2/resources",'
' "SUPPORTPATH": "/opt/senzing/data"'
' },'
' "SQL": {'
' "BACKEND": "SQL",'
f' "CONNECTION":"postgresql://{database_user_name}:{database_password}@{database_host_core}:{database_port_core}:{database_name}"'
' }'
'}')
else:
response_data["ConfigJSON"] = (
'{'
' "PIPELINE": {'
' "CONFIGPATH": "/etc/opt/senzing",'
f' "LICENSESTRINGBASE64": "{license_string}",'
' "RESOURCEPATH": "/opt/senzing/g2/resources",'
' "SUPPORTPATH": "/opt/senzing/data"'
' },'
' "SQL": {'
' "BACKEND": "HYBRID",'
f' "CONNECTION":"postgresql://{database_user_name}:{database_password}@{database_host_core}:{database_port_core}:{database_name}"'
' },'
' "C1": {'
' "CLUSTER_SIZE": "1",'
f' "DB_1": "postgresql://{database_user_name}:{database_password}@{database_host_res}:{database_port_res}:{database_name}"'
' },'
' "C2": {'
' "CLUSTER_SIZE": "1",'
f' "DB_1": "postgresql://{database_user_name}:{database_password}@{database_host_libfeat}:{database_port_libfeat}:{database_name}"'
' },'
' "HYBRID": {'
' "LIB_FEAT": "C2",'
' "LIB_FEAT_HKEY": "C2",'
' "RES_FEAT": "C1",'
' "RES_FEAT_EKEY": "C1",'
' "RES_FEAT_LKEY": "C1",'