-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
4830 lines (4587 loc) · 153 KB
/
template.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"
Transform: AWS::Serverless-2016-10-31
Description: "A template to create the GOV.UK One login Account backend infrastructure"
Parameters:
UserServicesStoreTableName:
Type: String
Default: user_services
RawEventsStoreTableName:
Type: String
Default: raw_events
ActivityLogsStoreTableName:
Type: String
Default: activity_log
AlertingStackName:
Description: The name of the stack that defines the Alerting resources
Type: String
Default: platform-alerting
DummyEventStoreTableName:
Type: String
Default: dummy_events
Environment:
Description: "The environment type"
Type: "String"
AllowedValues:
- "demo"
- "dev"
- "build"
- "staging"
- "integration"
- "production"
ConstraintDescription: must be dev, build, staging, integration or production
VpcStackName:
Description: >
The name of the stack that defines the VPC in which this container will
run.
Type: String
Default: vpc-enhanced
CodeSigningConfigArn:
Type: String
Description: >
The ARN of the Code Signing Config to use, provided by the deployment pipeline
Default: "none"
PermissionsBoundary:
Type: String
Description: >
The ARN of the permissions boundary to apply to any role created by the template
Default: "none"
AccountManagementFrontendStackName:
Type: String
Default: account-mgmt-frontend
TestRoleArn:
Type: String
Description: The ARN of the role the post-deploy tests are run from
Default: "none"
ProductTagValue:
Description: Value for the Product Tag
Type: String
Default: GOV.UK Sign In
OwnerTagValue:
Description: Value for the Owner Tag
Type: String
Default: govuk-accounts-tech@digital.cabinet-office.gov.uk
SourceTagValue:
Description: Value for the Source Tag
Type: String
Default: alphagov/di-account-management-backend/deploy/template.yaml
SystemTagValue:
Description: Value for the System Tag
Type: String
Default: Accounts
Conditions:
UseCodeSigning:
Fn::Not:
- Fn::Equals:
- !Ref CodeSigningConfigArn
- "none"
UsePermissionsBoundary:
Fn::Not:
- Fn::Equals:
- !Ref PermissionsBoundary
- "none"
IsNotDevelopmentOrDemo:
Fn::Not:
- Fn::Or:
- Fn::Equals:
- !Ref Environment
- "dev"
- Fn::Equals:
- !Ref Environment
- "demo"
UseInternalEvents: !Or
- !Equals [!Ref Environment, demo]
- !Equals [!Ref Environment, dev]
- !Equals [!Ref Environment, build]
UseExternalEvents: !Or
- !Equals [!Ref Environment, staging]
- !Equals [!Ref Environment, integration]
- !Equals [!Ref Environment, production]
ExportLogsToSplunk:
Fn::Or:
- !Equals [!Ref Environment, staging]
- !Equals [!Ref Environment, integration]
- !Equals [!Ref Environment, production]
GrantTestPermissions:
Fn::Not:
- Fn::Equals:
- !Ref TestRoleArn
- "none"
UseCanaryDeployment: !Or
- !Equals [!Ref Environment, production]
- !Equals [!Ref Environment, integration]
Globals:
Function:
Environment:
Variables:
AWS_LAMBDA_EXEC_WRAPPER: /opt/dynatrace
DT_CONNECTION_AUTH_TOKEN: !Sub
- "{{resolve:secretsmanager:${SecretArn}:SecretString:DT_CONNECTION_AUTH_TOKEN}}"
- SecretArn:
!FindInMap [
EnvironmentConfiguration,
!Ref Environment,
dynatraceSecretArn,
]
DT_CONNECTION_BASE_URL: !Sub
- "{{resolve:secretsmanager:${SecretArn}:SecretString:DT_CONNECTION_BASE_URL}}"
- SecretArn:
!FindInMap [
EnvironmentConfiguration,
!Ref Environment,
dynatraceSecretArn,
]
DT_CLUSTER_ID: !Sub
- "{{resolve:secretsmanager:${SecretArn}:SecretString:DT_CLUSTER_ID}}"
- SecretArn:
!FindInMap [
EnvironmentConfiguration,
!Ref Environment,
dynatraceSecretArn,
]
DT_LOG_COLLECTION_AUTH_TOKEN: !Sub
- "{{resolve:secretsmanager:${SecretArn}:SecretString:DT_LOG_COLLECTION_AUTH_TOKEN}}"
- SecretArn:
!FindInMap [
EnvironmentConfiguration,
!Ref Environment,
dynatraceSecretArn,
]
DT_TENANT: !Sub
- "{{resolve:secretsmanager:${SecretArn}:SecretString:DT_TENANT}}"
- SecretArn:
!FindInMap [
EnvironmentConfiguration,
!Ref Environment,
dynatraceSecretArn,
]
DT_OPEN_TELEMETRY_ENABLE_INTEGRATION: "true"
Architectures: ["arm64"]
MemorySize: 128
KmsKeyArn: !GetAtt LambdaKMSKey.Arn
ReservedConcurrentExecutions: 10
Runtime: nodejs18.x
Timeout: 5
VpcConfig:
SubnetIds:
- Fn::ImportValue: !Sub "${VpcStackName}-ProtectedSubnetIdA"
- Fn::ImportValue: !Sub "${VpcStackName}-ProtectedSubnetIdB"
SecurityGroupIds:
- Fn::ImportValue: !Sub ${VpcStackName}-AWSServicesEndpointSecurityGroupId
CodeSigningConfigArn: !If
- UseCodeSigning
- !Ref CodeSigningConfigArn
- !Ref AWS::NoValue
PermissionsBoundary: !If
- UsePermissionsBoundary
- !Ref PermissionsBoundary
- !Ref AWS::NoValue
Layers:
- !Sub
- "{{resolve:secretsmanager:${SecretArn}:SecretString:NODEJS_LAYER}}"
- SecretArn:
!FindInMap [
EnvironmentConfiguration,
!Ref Environment,
dynatraceSecretArn,
]
AutoPublishAlias: live
DeploymentPreference:
Enabled: true
Type:
Fn::If:
- UseCanaryDeployment
- Linear10PercentEvery1Minute
- AllAtOnce
Role: !GetAtt CodeDeployServiceRole.Arn
Mappings:
InputQueue:
demo:
QueueArn: ""
KeyArn: ""
dev:
QueueArn: ""
KeyArn: ""
build:
QueueArn: ""
KeyArn: ""
staging:
QueueArn: "arn:aws:sqs:eu-west-2:178023842775:self-staging-EC-SQS-Output-Queue-accounts"
KeyArn: "arn:aws:kms:eu-west-2:178023842775:key/6dbe7362-a125-466b-a135-22c98c436f17"
integration:
QueueArn: "arn:aws:sqs:eu-west-2:729485541398:self-integration-EC-SQS-Output-Queue-accounts"
KeyArn: "arn:aws:kms:eu-west-2:729485541398:key/6a4b784e-2f75-4f39-8b27-0fdf2134ca28"
production:
QueueArn: "arn:aws:sqs:eu-west-2:451773080033:self-production-EC-SQS-Output-Queue-accounts"
KeyArn: "arn:aws:kms:eu-west-2:451773080033:key/e95d47b6-613d-4bea-93c9-d400cdfb31ee"
IPVCoreAccounts:
demo:
AccountNumber: ""
dev:
AccountNumber: ""
build:
AccountNumber: "457601271792"
staging:
AccountNumber: "335257547869"
integration:
AccountNumber: "991138514218"
production:
AccountNumber: "075701497069"
OrchestrationAccounts:
demo:
AccountNumber: ""
dev:
AccountNumber: ""
build:
AccountNumber: ""
staging:
AccountNumber: "758531536632"
integration:
AccountNumber: "761723964695"
production:
AccountNumber: "172348255554"
EnvironmentVariables:
### These environment variables are referenced further down the file.
### Please ensure that any variables defined for an environment are defined for _all_ environments.
### We are passing the version ID of AWS secrets as cloudformation does not retrieve updated secrets unless there is a change in the template file related to it.
demo:
GOVACCOUNTSPUBLISHINGAPIURL: "https://account-api.integration.publishing.service.gov.uk"
REPORTSUSPISCIOUSACTIVITYTEMPLATEID: "2b3170b5-159e-457f-a282-f30f6006dc32"
dev:
GOVACCOUNTSPUBLISHINGAPIURL: "https://account-api.integration.publishing.service.gov.uk"
REPORTSUSPISCIOUSACTIVITYTEMPLATEID: "2b3170b5-159e-457f-a282-f30f6006dc32"
build:
GOVACCOUNTSPUBLISHINGAPIURL: "https://account-api.staging.publishing.service.gov.uk"
REPORTSUSPISCIOUSACTIVITYTEMPLATEID: "2b3170b5-159e-457f-a282-f30f6006dc32"
staging:
GOVACCOUNTSPUBLISHINGAPIURL: "https://account-api.staging.publishing.service.gov.uk"
REPORTSUSPISCIOUSACTIVITYTEMPLATEID: "2b3170b5-159e-457f-a282-f30f6006dc32"
integration:
GOVACCOUNTSPUBLISHINGAPIURL: "https://account-api.integration.publishing.service.gov.uk"
REPORTSUSPISCIOUSACTIVITYTEMPLATEID: "0674c6e3-219c-4e3a-b04c-3786bac7f228"
production:
GOVACCOUNTSPUBLISHINGAPIURL: "https://account-api.publishing.service.gov.uk"
REPORTSUSPISCIOUSACTIVITYTEMPLATEID: "0674c6e3-219c-4e3a-b04c-3786bac7f228"
CredentialStoreAccounts:
demo:
AccountNumber: "013758878511"
dev:
AccountNumber: "013758878511"
build:
AccountNumber: "688341086169"
staging:
AccountNumber: "922902741880"
integration:
AccountNumber: "406416508755"
production:
AccountNumber: "499563136613"
AccountInterventionsService:
demo:
AccountNumber: "484907510598"
dev:
AccountNumber: "484907510598"
build:
AccountNumber: "565393035754"
staging:
AccountNumber: "863518416563"
integration:
AccountNumber: "217747075921"
production:
AccountNumber: "324281879537"
TxmaAccounts:
demo:
AccountNumber: "248098332657"
dev:
AccountNumber: "248098332657"
build:
AccountNumber: "750703655225"
staging:
AccountNumber: "178023842775"
integration:
AccountNumber: "729485541398"
production:
AccountNumber: "451773080033"
EnvironmentConfiguration:
demo:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
zendeskGroupIdSecretArn: arn:aws:secretsmanager:eu-west-2:654654326096:secret:/account-mgmt-backend/zendesk-group-id-token-jn0K88
zendeskTagsSecretArn: arn:aws:secretsmanager:eu-west-2:654654326096:secret:/account-mgmt-backend/zendesk-tags-key-o0yqP7
zendeskApiTokenSecretArn: arn:aws:secretsmanager:eu-west-2:654654326096:secret:/account-mgmt-backend/zendesk-api-token-9OK6kw
zendeskApiUserSecretArn: arn:aws:secretsmanager:eu-west-2:654654326096:secret:/account-mgmt-backend/zendesk-api-user-key-xFarET
zendeskApiUrlSecretArn: arn:aws:secretsmanager:eu-west-2:654654326096:secret:/account-mgmt-backend/zendesk-api-url-key-0SJMs3
zendeskTicketFormIdSecretArn: arn:aws:secretsmanager:eu-west-2:654654326096:secret:/account-mgmt-backend/zendesk-ticket-form-id-key-KtEVtO
notifyApiKeySecretArn: arn:aws:secretsmanager:eu-west-2:654654326096:secret:/account-mgmt-backend/notify-api-key-rUzQp4
publishingApiKeyArn: arn:aws:secretsmanager:eu-west-2:654654326096:secret:/account-mgmt-frontend/Config/Publishing/API/Key-BVQ1hM
publishingApiKeyVersionId: "2c654686-68a5-459d-005a-39689b8b6937"
dev:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
zendeskGroupIdSecretArn: arn:aws:secretsmanager:eu-west-2:985326104449:secret:/account-mgmt-backend/zendesk-group-id-token-1O5AvL
zendeskTagsSecretArn: arn:aws:secretsmanager:eu-west-2:985326104449:secret:/account-mgmt-backend/zendesk-tags-key-itMbyV
zendeskApiTokenSecretArn: arn:aws:secretsmanager:eu-west-2:985326104449:secret:/account-mgmt-backend/zendesk-api-token-urjQGc
zendeskApiUserSecretArn: arn:aws:secretsmanager:eu-west-2:985326104449:secret:/account-mgmt-backend/zendesk-api-user-key-oPuZZU
zendeskApiUrlSecretArn: arn:aws:secretsmanager:eu-west-2:985326104449:secret:/account-mgmt-backend/zendesk-api-url-key-nhK90l
zendeskTicketFormIdSecretArn: arn:aws:secretsmanager:eu-west-2:985326104449:secret:/account-mgmt-backend/zendesk-ticket-form-id-key-QsdIP7
notifyApiKeySecretArn: arn:aws:secretsmanager:eu-west-2:985326104449:secret:/account-mgmt-backend/notify-api-key-4P84y7
publishingApiKeyArn: arn:aws:secretsmanager:eu-west-2:985326104449:secret:/account-mgmt-frontend/Config/Publishing/API/Key-FecC4U
publishingApiKeyVersionId: "1795b84e-bda5-449e-b7de-172aeded65de"
build:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
zendeskGroupIdSecretArn: arn:aws:secretsmanager:eu-west-2:301577035144:secret:/account-mgmt-backend/zendesk-group-id-token-Ve5ojs
zendeskTagsSecretArn: arn:aws:secretsmanager:eu-west-2:301577035144:secret:/account-mgmt-backend/zendesk-tags-key-H64ZpC
zendeskApiTokenSecretArn: arn:aws:secretsmanager:eu-west-2:301577035144:secret:/account-mgmt-backend/zendesk-api-token-ayNIV1
zendeskApiUserSecretArn: arn:aws:secretsmanager:eu-west-2:301577035144:secret:/account-mgmt-backend/zendesk-api-user-key-7jR9fV
zendeskApiUrlSecretArn: arn:aws:secretsmanager:eu-west-2:301577035144:secret:/account-mgmt-backend/zendesk-api-url-key-UpWdv7
zendeskTicketFormIdSecretArn: arn:aws:secretsmanager:eu-west-2:301577035144:secret:/account-mgmt-backend/zendesk-ticket-form-id-key-XYDm7B
notifyApiKeySecretArn: arn:aws:secretsmanager:eu-west-2:301577035144:secret:/account-mgmt-backend/notify-api-key-8vHJMb
publishingApiKeyArn: arn:aws:secretsmanager:eu-west-2:301577035144:secret:/account-mgmt-frontend/Config/Publishing/API/Key-BnpEHJ
publishingApiKeyVersionId: "b6b498c9-64d7-4655-a6cc-828aa82f0136"
staging:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
zendeskGroupIdSecretArn: arn:aws:secretsmanager:eu-west-2:539729775994:secret:/account-mgmt-backend/zendesk-group-id-token-HE0BjN
zendeskTagsSecretArn: arn:aws:secretsmanager:eu-west-2:539729775994:secret:/account-mgmt-backend/zendesk-tags-key-IFQKUB
zendeskApiTokenSecretArn: arn:aws:secretsmanager:eu-west-2:539729775994:secret:/account-mgmt-backend/zendesk-api-token-5HZvs4
zendeskApiUserSecretArn: arn:aws:secretsmanager:eu-west-2:539729775994:secret:/account-mgmt-backend/zendesk-api-user-key-0AiaN0
zendeskApiUrlSecretArn: arn:aws:secretsmanager:eu-west-2:539729775994:secret:/account-mgmt-backend/zendesk-api-url-key-wGN16k
zendeskTicketFormIdSecretArn: arn:aws:secretsmanager:eu-west-2:539729775994:secret:/account-mgmt-backend/zendesk-ticket-form-id-key-e9yPTR
notifyApiKeySecretArn: arn:aws:secretsmanager:eu-west-2:539729775994:secret:/account-mgmt-backend/notify-api-key-lSCNeM
publishingApiKeyArn: arn:aws:secretsmanager:eu-west-2:539729775994:secret:/account-mgmt-frontend/Config/Publishing/API/Key-ubkHIz
publishingApiKeyVersionId: "1fec2ee5-a02c-41e5-9227-185ac11bc1eb"
integration:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables
zendeskGroupIdSecretArn: arn:aws:secretsmanager:eu-west-2:666500506359:secret:/account-mgmt-backend/zendesk-group-id-token-djJbv6
zendeskTagsSecretArn: arn:aws:secretsmanager:eu-west-2:666500506359:secret:/account-mgmt-backend/zendesk-tags-key-q35WDl
zendeskApiTokenSecretArn: arn:aws:secretsmanager:eu-west-2:666500506359:secret:/account-mgmt-backend/zendesk-api-token-fByFIz
zendeskApiUserSecretArn: arn:aws:secretsmanager:eu-west-2:666500506359:secret:/account-mgmt-backend/zendesk-api-user-key-oVvUI5
zendeskApiUrlSecretArn: arn:aws:secretsmanager:eu-west-2:666500506359:secret:/account-mgmt-backend/zendesk-api-url-key-b5ToSY
zendeskTicketFormIdSecretArn: arn:aws:secretsmanager:eu-west-2:666500506359:secret:/account-mgmt-backend/zendesk-ticket-form-id-key-2iXqu6
notifyApiKeySecretArn: arn:aws:secretsmanager:eu-west-2:666500506359:secret:/account-mgmt-backend/notify-api-key-nvDui4
publishingApiKeyArn: arn:aws:secretsmanager:eu-west-2:666500506359:secret:/account-mgmt-frontend/Config/Publishing/API/Key-qWrhy3
publishingApiKeyVersionId: "279a0631-b5c2-4224-94bf-b8d94bda588b"
production:
dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceProductionVariables
zendeskGroupIdSecretArn: arn:aws:secretsmanager:eu-west-2:026991849909:secret:/account-mgmt-backend/zendesk-group-id-token-mE55Wr
zendeskTagsSecretArn: arn:aws:secretsmanager:eu-west-2:026991849909:secret:/account-mgmt-backend/zendesk-tags-key-FAHfJf
zendeskApiTokenSecretArn: arn:aws:secretsmanager:eu-west-2:026991849909:secret:/account-mgmt-backend/zendesk-api-token-aZOj3s
zendeskApiUserSecretArn: arn:aws:secretsmanager:eu-west-2:026991849909:secret:/account-mgmt-backend/zendesk-api-user-key-cMCENu
zendeskApiUrlSecretArn: arn:aws:secretsmanager:eu-west-2:026991849909:secret:/account-mgmt-backend/zendesk-api-url-key-WNGekL
zendeskTicketFormIdSecretArn: arn:aws:secretsmanager:eu-west-2:026991849909:secret:/account-mgmt-backend/zendesk-ticket-form-id-key-cAmu3i
notifyApiKeySecretArn: arn:aws:secretsmanager:eu-west-2:026991849909:secret:/account-mgmt-backend/notify-api-key-Ve4Yk1
publishingApiKeyArn: arn:aws:secretsmanager:eu-west-2:026991849909:secret:/account-mgmt-frontend/Config/Publishing/API/Key-3ZxzC4
publishingApiKeyVersionId: "a95cff2e-397a-4103-a032-864e0727e618"
Resources:
######################################
# Dummy events store
######################################
DummyEventStore:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: timestamp
AttributeType: N
BillingMode: PAY_PER_REQUEST
TableName: !Ref DummyEventStoreTableName
KeySchema:
- AttributeName: id
KeyType: HASH
- AttributeName: timestamp
KeyType: RANGE
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
SSESpecification:
SSEEnabled: true
SSEType: KMS
KMSMasterKeyId: !GetAtt DatabaseKmsKey.Arn
StreamSpecification:
StreamViewType: NEW_IMAGE
Tags:
- Key: Product
Value: GOV.UK Sign In
- Key: System
Value: Account Management Backend
- Key: Owner
Value: govuk-accounts-tech@digital.cabinet-office.gov.uk
- Key: Environment
Value: !Ref "Environment"
- Key: Source
Value: "https://github.com/alphagov/di-account-management-backend/blob/main/infrastructure/template.yaml"
######################################
# Raw events store
######################################
RawEventsStore:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: timestamp
AttributeType: N
BillingMode: PAY_PER_REQUEST
TableName: !Ref RawEventsStoreTableName
KeySchema:
- AttributeName: id
KeyType: HASH
- AttributeName: timestamp
KeyType: RANGE
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
SSESpecification:
SSEEnabled: true
SSEType: KMS
KMSMasterKeyId: !GetAtt DatabaseKmsKey.Arn
StreamSpecification:
StreamViewType: NEW_IMAGE
TimeToLiveSpecification:
AttributeName: remove_at
Enabled: true
Tags:
- Key: Product
Value: GOV.UK Sign In
- Key: System
Value: Account Management Backend
- Key: Owner
Value: govuk-accounts-tech@digital.cabinet-office.gov.uk
- Key: Environment
Value: !Ref "Environment"
- Key: Source
Value: "https://github.com/alphagov/di-account-management-backend/blob/main/infrastructure/template.yaml"
######################################
# User services store
######################################
UserServicesStore:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
AttributeDefinitions:
- AttributeName: user_id
AttributeType: S
BillingMode: PAY_PER_REQUEST
TableName: !Ref UserServicesStoreTableName
KeySchema:
- AttributeName: user_id
KeyType: HASH
Tags:
- Key: Product
Value: GOV.UK Sign In
- Key: System
Value: Account Management Backend
- Key: Owner
Value: govuk-accounts-tech@digital.cabinet-office.gov.uk
- Key: Environment
Value: !Ref "Environment"
- Key: Source
Value: "https://github.com/alphagov/di-account-management-backend/blob/main/infrastructre/template.yaml"
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
SSESpecification:
SSEEnabled: true
SSEType: KMS
KMSMasterKeyId: !GetAtt DatabaseKmsKey.Arn
#########################
# User Activity Log store
#########################
UserActivityLogsStore:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
AttributeDefinitions:
- AttributeName: user_id
AttributeType: S
- AttributeName: session_id
AttributeType: S
- AttributeName: event_id
AttributeType: S
GlobalSecondaryIndexes:
- IndexName: SessionIdIndex
KeySchema:
- AttributeName: session_id
KeyType: HASH
Projection:
ProjectionType: ALL
BillingMode: PAY_PER_REQUEST
TableName: !Ref ActivityLogsStoreTableName
KeySchema:
- AttributeName: user_id
KeyType: HASH
- AttributeName: event_id
KeyType: RANGE
Tags:
- Key: Product
Value: GOV.UK Sign In
- Key: System
Value: Account Management Backend
- Key: Owner
Value: govuk-accounts-tech@digital.cabinet-office.gov.uk
- Key: Environment
Value: !Ref "Environment"
- Key: Source
Value: "https://github.com/alphagov/di-account-management-backend/blob/main/infrastructre/template.yaml"
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
SSESpecification:
SSEEnabled: true
SSEType: KMS
KMSMasterKeyId: !GetAtt DatabaseKmsKey.Arn
######################################
# TxMA Event Queue (Dummy for now)
######################################
TxMAInputDummyQueue:
Type: AWS::SQS::Queue
Properties:
KmsMasterKeyId: !GetAtt QueueKmsKey.Arn
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
TxMAInputDummyQueueOldestMessageAgeAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName:
!Join [
"-",
[
!Ref AWS::StackName,
!Ref Environment,
TxMAInputDummyQueueOldestMessageAgeAlarm,
],
]
MetricName: ApproximateAgeOfOldestMessage
Namespace: AWS/SQS
Statistic: Maximum
Period: 300
EvaluationPeriods: 1
Threshold: 300
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: QueueName
Value: !GetAtt TxMAInputDummyQueue.QueueName
AlarmActions:
- !Sub "{{resolve:ssm:/${AlertingStackName}/SNS/LowAlertNotificationTopic/ARN}}"
########################################
# Output queue for audit events to TxMA
########################################
AuditOutputQueue:
Type: AWS::SQS::Queue
Properties:
KmsMasterKeyId: !Ref AuditEncryptionKey
MessageRetentionPeriod: 1209600
VisibilityTimeout: 70
RedrivePolicy:
deadLetterTargetArn: !GetAtt AuditDeadLetterQueue.Arn
maxReceiveCount: 5
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
AuditOutputQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !Ref AuditOutputQueue
PolicyDocument:
Statement:
- Effect: Allow
Principal:
AWS: !FindInMap [TxmaAccounts, !Ref Environment, AccountNumber]
Action:
- sqs:ChangeMessageVisibility
- sqs:DeleteMessage
- sqs:GetQueueAttributes
- sqs:ReceiveMessage
Resource: !GetAtt AuditOutputQueue.Arn
AuditDeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
KmsMasterKeyId: !Ref AuditEncryptionKey
MessageRetentionPeriod: 1209600
RedriveAllowPolicy:
redrivePermission: allowAll
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
AuditEncryptionKey:
Type: AWS::KMS::Key
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Properties:
EnableKeyRotation: true
KeyPolicy:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
Action: kms:*
Resource:
- "*"
- Effect: Allow
Principal:
AWS: !FindInMap [TxmaAccounts, !Ref Environment, AccountNumber]
Action: kms:Decrypt
Resource:
- "*"
AuditEncryptionKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: !Sub "alias/${AWS::StackName}/${Environment}/AuditEncryptionKey"
TargetKeyId: !Ref AuditEncryptionKey
AuditQueueArnParameter:
Type: AWS::SSM::Parameter
Properties:
Description: The ARN of the audit event output queue
Name: !Sub "/${AWS::StackName}/SQS/AuditQueue/ARN"
Type: String
Value: !GetAtt AuditOutputQueue.Arn
AuditQueueUrlParameter:
Type: AWS::SSM::Parameter
Properties:
Description: The URL of the audit event output queue
Name: !Sub "/${AWS::StackName}/SQS/AuditQueue/URL"
Type: String
Value: !Ref AuditOutputQueue
AuditQueueKeyArnParameter:
Type: AWS::SSM::Parameter
Properties:
Description: The ARN of the KMS key encrypting the audit event output queue
Name: !Sub "/${AWS::StackName}/KMS/AuditQueueKey/ARN"
Type: String
Value: !GetAtt AuditEncryptionKey.Arn
AuditOutputQueueOldestMessageAgeAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName:
!Join [
"-",
[
!Ref AWS::StackName,
!Ref Environment,
AuditOutputQueueOldestMessageAgeAlarm,
],
]
MetricName: ApproximateAgeOfOldestMessage
Namespace: AWS/SQS
Statistic: Maximum
Period: 300
EvaluationPeriods: 1
Threshold: 300
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: QueueName
Value: !GetAtt AuditOutputQueue.QueueName
AlarmActions:
- !Sub "{{resolve:ssm:/${AlertingStackName}/SNS/LowAlertNotificationTopic/ARN}}"
AuditDeadLetterQueueOldestMessageAgeAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName:
!Join [
"-",
[
!Ref AWS::StackName,
!Ref Environment,
AuditDeadLetterQueueOldestMessageAgeAlarm,
],
]
MetricName: ApproximateAgeOfOldestMessage
Namespace: AWS/SQS
Statistic: Maximum
Period: 300
EvaluationPeriods: 1
Threshold: 300
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: QueueName
Value: !GetAtt AuditDeadLetterQueue.QueueName
AlarmActions:
- !Sub "{{resolve:ssm:/${AlertingStackName}/SNS/LowAlertNotificationTopic/ARN}}"
######################
# Save Raw Events
######################
SaveRawEventsFunction:
Type: AWS::Serverless::Function
DependsOn:
- SaveRawEventsFunctionLogGroup
Properties:
FunctionName: !Sub ${Environment}-${AWS::StackName}-save-raw-events
CodeUri: src
PackageType: Zip
MemorySize: 220
Events:
InputQueue:
Type: SQS
Properties:
Queue: !If
- UseInternalEvents
- !GetAtt TxMAInputDummyQueue.Arn
- !FindInMap [InputQueue, !Ref Environment, QueueArn]
DeadLetterQueue:
Type: SQS
TargetArn: !GetAtt SaveRawEventsDeadLetterQueue.Arn
Handler: save-raw-events.handler
Role: !GetAtt SaveRawEventsRole.Arn
ReservedConcurrentExecutions: 30
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: 30
Environment:
Variables:
TABLE_NAME: !Ref RawEventsStoreTableName
NODE_OPTIONS: --enable-source-maps
DeploymentPreference:
Alarms:
- !Ref SaveRawEventsFunctionSuccessRate
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: true
Format: "esm"
OutExtension:
- .js=.mjs
Target: "es2020"
Sourcemap: true
EntryPoints:
- save-raw-events.ts
Banner:
- js=import { createRequire } from 'module'; const require = createRequire(import.meta.url);
SaveRawEventsDeadLetterQueue:
Type: AWS::SQS::Queue
DeletionPolicy: Delete
UpdateReplacePolicy: Delete
Properties:
MessageRetentionPeriod: 1209600
KmsMasterKeyId: !GetAtt QueueKmsKey.Arn
SaveRawEventsRole:
Type: AWS::IAM::Role
Properties:
PermissionsBoundary: !If
- UsePermissionsBoundary
- !Ref PermissionsBoundary
- !Ref AWS::NoValue
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
- !Ref SaveRawEventsPolicy
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- "sts:AssumeRole"
SaveRawEventsPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- sqs:ReceiveMessage
- sqs:DeleteMessage
- sqs:GetQueueAttributes
Resource: !If
- UseInternalEvents
- !GetAtt TxMAInputDummyQueue.Arn
- !FindInMap [InputQueue, !Ref Environment, QueueArn]
- Effect: Allow
Action:
- sqs:SendMessage
Resource: !GetAtt SaveRawEventsDeadLetterQueue.Arn
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:UpdateItem
Resource:
- !GetAtt RawEventsStore.Arn
- !Sub
- "${Arn}/*"
- Arn: !GetAtt RawEventsStore.Arn
- Effect: Allow
Action:
- kms:Decrypt
- kms:GenerateDataKey*
- kms:ReEncrypt*
Resource:
- !GetAtt QueueKmsKey.Arn
- !GetAtt DatabaseKmsKey.Arn
- !If
- UseInternalEvents
- !Ref AWS::NoValue
- !FindInMap [InputQueue, !Ref Environment, KeyArn]
SaveRawEventsFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${Environment}-${AWS::StackName}-save-raw-events"
RetentionInDays: 30
KmsKeyId: !GetAtt LoggingKmsKey.Arn
SaveRawEventsCSLSSubscription:
Condition: ExportLogsToSplunk
Type: AWS::Logs::SubscriptionFilter
Properties:
DestinationArn: !Sub "{{resolve:ssm:/${Environment}/Platform/Logs/Subscription/CSLS/ARN}}"
FilterPattern: ""
LogGroupName: !Ref SaveRawEventsFunctionLogGroup
SaveRawEventsDLQAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName:
!Join [
"-",
[!Ref AWS::StackName, !Ref Environment, SaveRawEventsDLQAlarm],
]
AlarmDescription: More than 1 raw event failed to be saved in the last 5 minutes.
Namespace: "AWS/SQS"
MetricName: "ApproximateNumberOfMessagesVisible"
Dimensions:
- Name: "QueueName"
Value: !GetAtt SaveRawEventsDeadLetterQueue.QueueName
Statistic: "Sum"
Period: 300
EvaluationPeriods: 1
Threshold: 1
ComparisonOperator: "GreaterThanOrEqualToThreshold"
AlarmActions:
- !Sub "{{resolve:ssm:/${AlertingStackName}/SNS/LowAlertNotificationTopic/ARN}}"
ActionsEnabled: true
SaveRawEventsDeadLetterQueueOldestMessageAgeAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName:
!Join [
"-",
[
!Ref AWS::StackName,
!Ref Environment,
SaveRawEventsDeadLetterQueueOldestMessageAgeAlarm,
],
]
MetricName: ApproximateAgeOfOldestMessage
Namespace: AWS/SQS
Statistic: Maximum
Period: 300
EvaluationPeriods: 1
Threshold: 300
ComparisonOperator: GreaterThanOrEqualToThreshold
Dimensions:
- Name: QueueName
Value: !GetAtt SaveRawEventsDeadLetterQueue.QueueName
AlarmActions:
- !Sub "{{resolve:ssm:/${AlertingStackName}/SNS/LowAlertNotificationTopic/ARN}}"
SaveRawEventsFunctionSuccessRate:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName:
!Join [
"-",
[
!Ref AWS::StackName,
!Ref Environment,
SaveRawEventsFunctionSuccessRate,
],
]
Metrics:
- Id: errors
MetricStat:
Metric:
Namespace: AWS/Lambda
MetricName: Errors
Dimensions:
- Name: FunctionName
Value: !Ref SaveRawEventsFunction
Period: 300
Stat: Sum
ReturnData: false
- Id: invocations
MetricStat:
Metric:
Namespace: AWS/Lambda
MetricName: Invocations
Dimensions:
- Name: FunctionName
Value: !Ref SaveRawEventsFunction
Period: 300
Stat: Sum
ReturnData: false
- Id: successRate
Expression: "1 - (errors / invocations)"
Label: "Success Rate"
ReturnData: true
Threshold: 0.95
ComparisonOperator: LessThanThreshold
EvaluationPeriods: 1
AlarmActions:
- !Sub "{{resolve:ssm:/${AlertingStackName}/SNS/LowAlertNotificationTopic/ARN}}"
########################
# Querying User Services
########################
QueryUserServicesFunction:
Type: AWS::Serverless::Function
DependsOn:
- QueryUserServicesFunctionLogGroup
Properties:
FunctionName: !Sub ${Environment}-${AWS::StackName}-query-user-services
CodeUri: src
PackageType: Zip
MemorySize: 250
Events:
DynamoStream:
Type: DynamoDB
Properties:
BatchSize: 1
Stream: !GetAtt RawEventsStore.StreamArn
Enabled: true
DestinationConfig:
OnFailure:
Destination: !GetAtt QueryUserServicesDeadLetterQueue.Arn
StartingPosition: LATEST
FilterCriteria:
Filters:
- Pattern: '{ "eventName": ["INSERT"] }'
DeadLetterQueue:
Type: SQS
TargetArn: !GetAtt QueryUserServicesDeadLetterQueue.Arn
Handler: query-user-services.handler
Role: !GetAtt QueryUserServicesRole.Arn
ReservedConcurrentExecutions: 30
ProvisionedConcurrencyConfig: