-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.yaml
More file actions
902 lines (821 loc) · 32.8 KB
/
main.yaml
File metadata and controls
902 lines (821 loc) · 32.8 KB
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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: |
PSU lambda functions and related resources
Globals:
Function:
Timeout: 50
MemorySize: 256
Architectures:
- x86_64
Runtime: nodejs24.x
Environment:
Variables:
NODE_OPTIONS: "--enable-source-maps"
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:580247275435:layer:LambdaInsightsExtension:49
Parameters:
StackName:
Type: String
Default: none
PrescriptionStatusUpdatesTableName:
Type: String
Default: none
PrescriptionNotificationStatesTableName:
Type: String
Default: none
NHSNotifyPrescriptionsSQSQueueUrl:
Type: String
Default: none
PostDatedNotificationsSQSQueueUrl:
Type: String
Default: none
SQSSaltSecret:
Type: AWS::SecretsManager::Secret::Name<String>
EnabledSiteODSCodesParam:
Type: AWS::SSM::Parameter::Name<String>
EnabledSystemsParam:
Type: AWS::SSM::Parameter::Name<String>
BlockedSiteODSCodesParam:
Type: AWS::SSM::Parameter::Name<String>
NotifyRoutingPlanIDParam:
Type: AWS::SSM::Parameter::Name<String>
NotifyAPIBaseURLParam:
Type: AWS::SSM::Parameter::Name<String>
EnableNotificationsExternalParam:
Type: AWS::SSM::Parameter::Name<String>
EnableNotificationsInternalParam:
Type: AWS::SSM::Parameter::Name<String>
EnablePostDatedNotifications:
Type: AWS::SSM::Parameter::Name<String>
Default: "false"
RequireApplicationName:
Type: String
Default: false
AllowedValues:
- true
- false
LogLevel:
Type: String
LogRetentionInDays:
Type: Number
EnableSplunk:
Type: String
VersionNumber:
Type: String
CommitId:
Type: String
DeployCheckPrescriptionStatusUpdate:
Type: String
DeployNotificationsReporting:
Type: String
Default: false
Environment:
Type: String
EnableBackup:
Type: String
TestPrescriptionsParamName1:
Type: AWS::SSM::Parameter::Name<String>
TestPrescriptionsParamName2:
Type: AWS::SSM::Parameter::Name<String>
TestPrescriptionsParamName3:
Type: AWS::SSM::Parameter::Name<String>
TestPrescriptionsParamName4:
Type: AWS::SSM::Parameter::Name<String>
Conditions:
ShouldDeployCheckPrescriptionStatusUpdate: !Equals
- true
- !Ref DeployCheckPrescriptionStatusUpdate
ShouldDeployNotificationsReporting: !Equals
- true
- !Ref DeployNotificationsReporting
EnableBackupCondition: !Equals
- "True"
- !Ref EnableBackup
Resources:
UpdatePrescriptionStatus:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-UpdatePrescriptionStatus
CodeUri: ../../packages
Handler: updatePrescriptionStatus.handler
Role: !GetAtt UpdatePrescriptionStatusResources.Outputs.LambdaRoleArn
Environment:
Variables:
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
POST_DATED_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref PostDatedNotificationsSQSQueueUrl
ENABLE_POST_DATED_NOTIFICATIONS: !Ref EnablePostDatedNotifications
SQS_SALT: !Ref SQSSaltSecret
ENABLED_SITE_ODS_CODES_PARAM: !Ref EnabledSiteODSCodesParam
ENABLED_SYSTEMS_PARAM: !Ref EnabledSystemsParam
BLOCKED_SITE_ODS_CODES_PARAM: !Ref BlockedSiteODSCodesParam
ENABLE_NOTIFICATIONS_PARAM: !Ref EnableNotificationsInternalParam
LOG_LEVEL: !Ref LogLevel
ENVIRONMENT: !Ref Environment
REQUIRE_APPLICATION_NAME: !Ref RequireApplicationName
TEST_PRESCRIPTIONS_PARAM_NAME_1: !Ref TestPrescriptionsParamName1
TEST_PRESCRIPTIONS_PARAM_NAME_2: !Ref TestPrescriptionsParamName2
TEST_PRESCRIPTIONS_PARAM_NAME_3: !Ref TestPrescriptionsParamName3
TEST_PRESCRIPTIONS_PARAM_NAME_4: !Ref TestPrescriptionsParamName4
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: updatePrescriptionStatus/tsconfig.json
packages: bundle
EntryPoints:
- updatePrescriptionStatus/src/updatePrescriptionStatus.ts
UpdatePrescriptionStatusResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-UpdatePrescriptionStatus
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-UpdatePrescriptionStatus
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
- - Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionStatusUpdatesTableName}:TableWritePolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionStatusUpdatesTableName}:TableReadPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionStatusUpdatesKMSKeyPolicyArn
- Fn::ImportValue: !Sub ${StackName}-UseNotificationSQSQueueKMSKeyPolicyArn
- Fn::ImportValue: !Sub ${StackName}-WriteNHSNotifyPrescriptionsSQSQueuePolicyArn
- Fn::ImportValue: !Sub ${StackName}-WritePostDatedNotificationsSQSQueuePolicyArn
- Fn::ImportValue: !Sub ${StackName}-GetSQSSaltSecretPolicy
- Fn::ImportValue: !Sub ${StackName}-GetNotificationsParameterPolicy
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
ConvertRequestToFhirFormat:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-ConvertRequestToFhirFormat
CodeUri: ../../packages
Handler: cpsu.format_1_handler
Role: !GetAtt ConvertRequestToFhirFormatResources.Outputs.LambdaRoleArn
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: cpsuLambda/tsconfig.json
packages: bundle
EntryPoints:
- cpsuLambda/src/cpsu.ts
ConvertRequestToFhirFormatResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-ConvertRequestToFhirFormat
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-ConvertRequestToFhirFormat
IncludeAdditionalPolicies: false
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
GetStatusUpdates:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-GetStatusUpdates
CodeUri: ../../packages
Handler: getStatusUpdates.handler
Role: !GetAtt GetStatusUpdatesResources.Outputs.LambdaRoleArn
Environment:
Variables:
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName
LOG_LEVEL: !Ref LogLevel
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: gsul/tsconfig.json
packages: bundle
EntryPoints:
- gsul/src/getStatusUpdates.ts
GetStatusUpdatesResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-GetStatusUpdates
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-GetStatusUpdates
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
- - Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionStatusUpdatesTableName}:TableReadPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionStatusUpdatesKMSKeyPolicyArn
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
Status:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-status
CodeUri: ../../packages
Handler: statusLambda.handler
Role: !GetAtt StatusResources.Outputs.LambdaRoleArn
Environment:
Variables:
VERSION_NUMBER: !Ref VersionNumber
COMMIT_ID: !Ref CommitId
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: statusLambda/tsconfig.json
packages: bundle
EntryPoints:
- statusLambda/src/statusLambda.ts
StatusResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-status
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-status
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
- - !ImportValue account-resources:LambdaAccessSecretsPolicy
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
CapabilityStatement:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-CapabilityStatement
CodeUri: ../../packages
Handler: capabilityStatement.handler
Role: !GetAtt CapabilityStatementResources.Outputs.LambdaRoleArn
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: capabilityStatement/tsconfig.json
packages: bundle
EntryPoints:
- capabilityStatement/src/capabilityStatement.ts
CapabilityStatementResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-CapabilityStatement
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-CapabilityStatement
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
CheckPrescriptionStatusUpdates:
Condition: ShouldDeployCheckPrescriptionStatusUpdate
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-CheckPrescriptionStatusUpdates
CodeUri: ../../packages
Handler: checkPrescriptionStatusUpdates.handler
Role: !GetAtt CheckPrescriptionStatusUpdatesResources.Outputs.LambdaRoleArn
Environment:
Variables:
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName
LOG_LEVEL: !Ref LogLevel
MIN_RESULTS_RETURNED: 5
MAX_RESULTS_RETURNED: 15
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: checkPrescriptionStatusUpdates/tsconfig.json
EntryPoints:
- checkPrescriptionStatusUpdates/src/checkPrescriptionStatusUpdates.ts
CheckPrescriptionStatusUpdatesResources:
Condition: ShouldDeployCheckPrescriptionStatusUpdate
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-CheckPrescriptionStatusUpdates
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-CheckPrescriptionStatusUpdates
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
- - Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionStatusUpdatesTableName}:TableReadPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionStatusUpdatesKMSKeyPolicyArn
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
NotificationsReporting:
Condition: ShouldDeployNotificationsReporting
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-NotificationsReporting
CodeUri: ../../packages
Handler: notificationsReportingLambda.handler
Role: !GetAtt NotificationsReportingResources.Outputs.LambdaRoleArn
Environment:
Variables:
TABLE_NAME: !Ref PrescriptionNotificationStatesTableName
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: notificationsReportingLambda/tsconfig.json
packages: bundle
EntryPoints:
- notificationsReportingLambda/src/notificationsReportingLambda.ts
NotificationsReportingResources:
Condition: ShouldDeployNotificationsReporting
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-NotificationsReporting
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-NotificationsReporting
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
- - Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableReadPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionNotificationStatesKMSKeyPolicyArn
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
NotifyProcessorScheduleEventRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- scheduler.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- !Ref NotifyProcessorScheduleEventRolePolicy
NotifyProcessorScheduleEventRolePolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !GetAtt NotifyProcessor.Arn
NotifyProcessor:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-NotifyProcessor
Timeout: 900 # 15 minutes
CodeUri: ../../packages/
Handler: nhsNotifyLambda.handler
Role: !GetAtt NotifyProcessorResources.Outputs.LambdaRoleArn
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
TABLE_NAME: !Ref PrescriptionNotificationStatesTableName
API_KEY_SECRET:
Fn::ImportValue: !Sub ${StackName}-PSU-Notify-API-Key
PRIVATE_KEY_SECRET:
Fn::ImportValue: !Sub ${StackName}-PSU-Notify-PrivateKey
KID_SECRET:
Fn::ImportValue: !Sub ${StackName}-PSU-Notify-KID
NHS_NOTIFY_ROUTING_ID_PARAM: !Ref NotifyRoutingPlanIDParam
NOTIFY_API_BASE_URL_PARAM: !Ref NotifyAPIBaseURLParam
MAKE_REAL_NOTIFY_REQUESTS_PARAM: !Ref EnableNotificationsExternalParam
Events:
ScheduleEvent:
Type: ScheduleV2
Properties:
Name: !Sub ${StackName}-NotifySchedule
ScheduleExpression: "rate(1 minute)"
RoleArn: !GetAtt NotifyProcessorScheduleEventRole.Arn
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: nhsNotifyLambda/tsconfig.json
packages: bundle
EntryPoints:
- nhsNotifyLambda/src/nhsNotifyLambda.ts
NotifyProcessorResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-NotifyProcessor
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-NotifyProcessor
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
- - Fn::ImportValue: !Sub ${StackName}-WriteNHSNotifyPrescriptionsSQSQueuePolicyArn
- Fn::ImportValue: !Sub ${StackName}-ReadNHSNotifyPrescriptionsSQSQueuePolicyArn
- Fn::ImportValue: !Sub ${StackName}-UseNotificationSQSQueueKMSKeyPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableReadPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableWritePolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionNotificationStatesKMSKeyPolicyArn
- Fn::ImportValue: !Sub ${StackName}-GetNotificationsParameterPolicy
- Fn::ImportValue: !Sub ${StackName}-GetPSUSecretPolicy
- Fn::ImportValue: !Sub ${StackName}-UsePSUSecretsKMSKeyPolicyArn
## Post-dated lambda definitions
PostDatedNotifyLambdaScheduleEventRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- scheduler.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- !Ref PostDatedNotifyLambdaScheduleEventRolePolicy
PostDatedNotifyLambdaScheduleEventRolePolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !GetAtt PostDatedNotifyLambda.Arn
PostDatedNotifyLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-postDatedNotifyLambda
Timeout: 900
CodeUri: ../../packages/
Handler: main.handler
Role: !GetAtt PostDatedNotifyLambdaResources.Outputs.LambdaRoleArn
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
POST_DATED_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref PostDatedNotificationsSQSQueueUrl
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName
Events:
ScheduleEvent:
Type: ScheduleV2
Properties:
Name: !Sub ${StackName}-PostDatedNotifySchedule
ScheduleExpression: "rate(15 minutes)"
RoleArn: !GetAtt PostDatedNotifyLambdaScheduleEventRole.Arn
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
packages: bundle
# set tsconfig path to whatever you actually have for this lambda package
tsconfig: postDatedLambda/tsconfig.json
EntryPoints:
- postDatedLambda/src/main.ts
PostDatedNotifyLambdaResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-postDatedNotifyLambda
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-postDatedNotifyLambda
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
- - Fn::ImportValue: !Sub ${StackName}-WriteNHSNotifyPrescriptionsSQSQueuePolicyArn
- Fn::ImportValue: !Sub ${StackName}-ReadNHSNotifyPrescriptionsSQSQueuePolicyArn
- Fn::ImportValue: !Sub ${StackName}-UseNotificationSQSQueueKMSKeyPolicyArn
- Fn::ImportValue: !Sub ${StackName}-WritePostDatedNotificationsSQSQueuePolicyArn
- Fn::ImportValue: !Sub ${StackName}-ReadPostDatedNotificationsSQSQueuePolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionStatusUpdatesTableName}:TableWritePolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionStatusUpdatesTableName}:TableReadPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionStatusUpdatesKMSKeyPolicyArn
## End of post-dated lambda bits
NHSNotifyUpdateCallback:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-NHSNotifyUpdateCallback
CodeUri: ../../packages/
Handler: lambdaHandler.handler
Role: !GetAtt NHSNotifyUpdateCallbackResources.Outputs.LambdaRoleArn
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
TABLE_NAME: !Ref PrescriptionNotificationStatesTableName
APP_ID_SECRET:
Fn::ImportValue: !Sub ${StackName}-PSU-Notify-Application-ID
API_KEY_SECRET:
Fn::ImportValue: !Sub ${StackName}-PSU-Notify-API-Key
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: nhsNotifyUpdateCallback/tsconfig.json
packages: bundle
EntryPoints:
- nhsNotifyUpdateCallback/src/lambdaHandler.ts
NHSNotifyUpdateCallbackResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-NHSNotifyUpdateCallback
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-NHSNotifyUpdateCallback
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
- - Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableReadPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableWritePolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionNotificationStatesKMSKeyPolicyArn
- Fn::ImportValue: !Sub ${StackName}-GetPSUSecretPolicy
- Fn::ImportValue: !Sub ${StackName}-UsePSUSecretsKMSKeyPolicyArn
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
PsuRestoreValidationPolicy:
Condition: EnableBackupCondition
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: !Sub ${StackName}-PsuRestoreValidationPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- backup:PutRestoreValidationResult
Resource: "*"
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:BatchGetItem
- dynamodb:Scan
- dynamodb:Query
- dynamodb:ConditionCheckItem
- dynamodb:DescribeTable
Resource: !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/awsbackup-restore-test-*
PsuRestoreValidation:
Condition: EnableBackupCondition
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-PsuRestoreValidation
CodeUri: ../../packages/
Handler: handler.handler
Role: !GetAtt PsuRestoreValidationResources.Outputs.LambdaRoleArn
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
Metadata:
BuildMethod: esbuild
guard:
SuppressedRules:
- LAMBDA_DLQ_CHECK
- LAMBDA_INSIDE_VPC
- LAMBDA_CONCURRENCY_CHECK
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
tsconfig: psuRestoreValidationLambda/tsconfig.json
packages: bundle
EntryPoints:
- psuRestoreValidationLambda/src/handler.ts
PsuRestoreValidationResources:
Condition: EnableBackupCondition
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-PsuRestoreValidation
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-PsuRestoreValidation
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
IncludeAdditionalPolicies: true
AdditionalPolicies: !Join
- ","
- - !Ref PsuRestoreValidationPolicy
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionStatusUpdatesTableName}:TableReadPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionStatusUpdatesKMSKeyPolicyArn
PsuRestoreValidationLambdaInvokePermission:
Condition: EnableBackupCondition
DependsOn:
- PsuBackupRestoreJobStateChangeRule
- PsuRestoreValidation
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:InvokeFunction"
FunctionName: !GetAtt PsuRestoreValidation.Arn
Principal: "events.amazonaws.com"
SourceArn: !GetAtt PsuBackupRestoreJobStateChangeRule.Arn
# EventBridge Rule for Backup Restore Job State Change
PsuBackupRestoreJobStateChangeRule:
Condition: EnableBackupCondition
Type: "AWS::Events::Rule"
Properties:
EventPattern:
source:
- "aws.backup"
detail-type:
- "Restore Job State Change"
detail:
resourceType:
- "DynamoDB.FullyManaged"
status:
- "COMPLETED"
sourceResourceArn:
- !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${PrescriptionStatusUpdatesTableName}
Targets:
- Arn: !GetAtt PsuRestoreValidation.Arn
Id: "RestoreTestingValidationFunction"
Outputs:
UpdatePrescriptionStatusFunctionName:
Description: The function name of the UpdatePrescriptionStatus lambda
Value: !Ref UpdatePrescriptionStatus
UpdatePrescriptionStatusFunctionArn:
Description: The function ARN of the UpdatePrescriptionStatus lambda
Value: !GetAtt UpdatePrescriptionStatus.Arn
GetStatusUpdatesFunctionName:
Description: The function name of the GetStatusUpdates lambda
Value: !Ref GetStatusUpdates
GetStatusUpdatesFunctionArn:
Description: The function ARN of the GetStatusUpdates lambda
Value: !GetAtt GetStatusUpdates.Arn
Export:
Name: !Sub ${StackName}:functions:GetStatusUpdates:FunctionArn
ConvertRequestToFhirFormatFunctionName:
Description: The function name of the Convert Request to Fhir Format lambda
Value: !Ref ConvertRequestToFhirFormat
ConvertRequestToFhirFormatFunctionArn:
Description: The function ARN of the ConvertRequestToFhirFormat lambda
Value: !GetAtt ConvertRequestToFhirFormat.Arn
Export:
Name: !Sub ${StackName}:functions:ConvertRequestToFhirFormat:FunctionArn
StatusFunctionName:
Description: The function name of the Status lambda
Value: !Ref Status
StatusFunctionArn:
Description: The function ARN of the Status lambda
Value: !GetAtt Status.Arn
CapabilityStatementFunctionName:
Description: The function name of the CapabilityStatement lambda
Value: !Ref CapabilityStatement
CapabilityStatementFunctionArn:
Description: The function ARN of the CapabilityStatement lambda
Value: !GetAtt CapabilityStatement.Arn
CheckPrescriptionStatusUpdatesFunctionName:
Description: The function name of the CheckPrescriptionStatusUpdates lambda
Value: !If
- ShouldDeployCheckPrescriptionStatusUpdate
- !Ref CheckPrescriptionStatusUpdates
- ""
CheckPrescriptionStatusUpdatesFunctionArn:
Description: The function ARN of the CheckPrescriptionStatusUpdates lambda
Value: !If
- ShouldDeployCheckPrescriptionStatusUpdate
- !GetAtt CheckPrescriptionStatusUpdates.Arn
- ""
NotifyProcessorFunctionName:
Description: The function name of the NHS Notify lambda
Value: !Ref NotifyProcessor
NotifyProcessorFunctionArn:
Description: The function ARN of the NHS Notify lambda
Value: !GetAtt NotifyProcessor.Arn
NHSNotifyUpdateCallbackFunctionName:
Description: The function name of the NHSNotifyUpdateCallback lambda
Value: !Ref NHSNotifyUpdateCallback
NHSNotifyUpdateCallbackFunctionArn:
Description: The function ARN of the NHSNotifyUpdateCallback lambda
Value: !GetAtt NHSNotifyUpdateCallback.Arn
NotificationsReportingFunctionName:
Description: The function name of the NotificationsReporting lambda
Value: !If
- ShouldDeployNotificationsReporting
- !Ref NotificationsReporting
- ""
NotificationsReportingFunctionArn:
Description: The function ARN of the NotificationsReporting lambda
Value: !If
- ShouldDeployNotificationsReporting
- !GetAtt NotificationsReporting.Arn
- ""
# Post-dated lambda outputs
PostDatedNotifyLambdaFunctionName:
Description: The function name of the postDatedNotifyLambda
Value: !Ref PostDatedNotifyLambda
PostDatedNotifyLambdaFunctionArn:
Description: The function ARN of the postDatedNotifyLambda
Value: !GetAtt PostDatedNotifyLambda.Arn