Skip to content

Commit ddddb2a

Browse files
authored
New: [AEA-5308] - Add NHS Notify callback lambda (#1634)
## Summary - ✨ New Feature ### Details Adds a lambda function which receives callback notification updates, and stores them in the relevant dynamo table
1 parent c011dfe commit ddddb2a

41 files changed

Lines changed: 1776 additions & 126 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/scripts/deploy_api.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,11 @@ fi
8585

8686
# Find and replace securitySchemes
8787
if [[ "${APIGEE_ENVIRONMENT}" == "prod" ]]; then
88-
if [[ "${API_TYPE}" == "standard" ]]; then
89-
jq '.components.securitySchemes."app-level3" = {"$ref": "https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/app-level3"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
90-
else
91-
jq '.components.securitySchemes."app-level0" = {"$ref": "https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/app-level0"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
92-
fi
88+
jq '.components.securitySchemes."app-level3" = {"$ref": "https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/app-level3"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
89+
jq '.components.securitySchemes."app-level0" = {"$ref": "https://proxygen.prod.api.platform.nhs.uk/components/securitySchemes/app-level0"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
9390
else
94-
if [[ "${API_TYPE}" == "standard" ]]; then
95-
jq '.components.securitySchemes."app-level3" = {"$ref": "https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/app-level3"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
96-
else
97-
jq '.components.securitySchemes."app-level0" = {"$ref": "https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/app-level0"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
98-
fi
91+
jq '.components.securitySchemes."app-level3" = {"$ref": "https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/app-level3"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
92+
jq '.components.securitySchemes."app-level0" = {"$ref": "https://proxygen.ptl.api.platform.nhs.uk/components/securitySchemes/app-level0"}' "${SPEC_PATH}" > temp.json && mv temp.json "${SPEC_PATH}"
9993
fi
10094

10195
# Remove target attributes if the environment is sandbox

.github/workflows/run_release_code_and_api.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ on:
8585
required: false
8686
REGRESSION_TESTS_PEM:
8787
required: true
88+
8889
jobs:
8990
release_code_and_api:
9091
runs-on: ubuntu-22.04

.vscode/eps-prescription-status-update-api.code-workspace

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"name": "packages/nhsNotifyLambda",
3333
"path": "../packages/nhsNotifyLambda"
3434
},
35+
{
36+
"name": "packages/nhsNotifyUpdateCallback",
37+
"path": "../packages/nhsNotifyUpdateCallback"
38+
},
3539
{
3640
"name": "packages/capabilityStatement",
3741
"path": "../packages/capabilityStatement"
@@ -97,6 +101,7 @@
97101
"mermade",
98102
"milliliter",
99103
"mkhl",
104+
"nhsapp",
100105
"nHSCHI",
101106
"NHSD",
102107
"nhsdlogin",

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ lint-node: compile-node
117117
npm run lint --workspace packages/cpsuLambda
118118
npm run lint --workspace packages/checkPrescriptionStatusUpdates
119119
npm run lint --workspace packages/nhsNotifyLambda
120+
npm run lint --workspace packages/nhsNotifyUpdateCallback
120121
npm run lint --workspace packages/common/testing
121122
npm run lint --workspace packages/common/middyErrorHandler
122123
npm run lint --workspace packages/common/commonTypes
@@ -147,6 +148,7 @@ test: compile
147148
npm run test --workspace packages/cpsuLambda
148149
npm run test --workspace packages/checkPrescriptionStatusUpdates
149150
npm run test --workspace packages/nhsNotifyLambda
151+
npm run test --workspace packages/nhsNotifyUpdateCallback
150152
npm run test --workspace packages/common/middyErrorHandler
151153

152154
clean:
@@ -164,6 +166,8 @@ clean:
164166
rm -rf packages/cpsuLambda/lib
165167
rm -rf packages/nhsNotifyLambda/coverage
166168
rm -rf packages/nhsNotifyLambda/lib
169+
rm -rf packages/nhsNotifyUpdateCallback/coverage
170+
rm -rf packages/nhsNotifyUpdateCallback/lib
167171
rm -rf packages/checkPrescriptionStatusUpdates/lib
168172
rm -rf packages/common/testing/lib
169173
rm -rf packages/common/middyErrorHandler/lib

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This is the AWS layer that provides an API for EPS Prescription Status Update.
2020
- `packages/capabilityStatement/` Returns a static capability statement.
2121
- `packages/cpsuLambda` Handles updating prescription status using a custom format.
2222
- `packages/nhsNotifyLambda` Handles sending prescription notifications to the NHS notify service.
23+
- `packages/nhsNotifyUpdateCallback` Handles receiving notification updates from the NHS notify service.
2324
- `scripts/` Utilities helpful to developers of this specification.
2425
- `postman/` Postman collections to call the APIs. Documentation on how to use them are in the collections.
2526
- `SAMtemplates/` Contains the SAM templates used to define the stacks.

SAMtemplates/apis/main.yaml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ Parameters:
5454
Type: String
5555
Default: none
5656

57+
NHSNotifyUpdateCallbackFunctionName:
58+
Type: String
59+
Default: none
60+
61+
NHSNotifyUpdateCallbackFunctionArn:
62+
Type: String
63+
Default: none
64+
5765
LogRetentionInDays:
5866
Type: Number
5967

@@ -427,6 +435,32 @@ Resources:
427435
- StatusCode: "400"
428436
- StatusCode: "500"
429437

438+
NotificationDeliveryStatusCallbackMethod:
439+
Type: AWS::ApiGateway::Method
440+
Properties:
441+
RestApiId: !Ref RestApiGateway
442+
ResourceId: !Ref NotificationDeliveryStatusCallbackResource
443+
HttpMethod: POST
444+
AuthorizationType: NONE # They authenticate with a signature header
445+
Integration:
446+
Type: AWS_PROXY
447+
Credentials: !GetAtt RestApiGatewayResources.Outputs.ApiGwRoleArn
448+
IntegrationHttpMethod: POST
449+
Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NHSNotifyUpdateCallbackFunctionArn}/invocations
450+
MethodResponses:
451+
- StatusCode: "202"
452+
- StatusCode: "401"
453+
- StatusCode: "403"
454+
- StatusCode: "429"
455+
- StatusCode: "500"
456+
457+
NotificationDeliveryStatusCallbackResource:
458+
Type: AWS::ApiGateway::Resource
459+
Properties:
460+
RestApiId: !Ref RestApiGateway
461+
ParentId: !GetAtt RestApiGateway.RootResourceId
462+
PathPart: notification-delivery-status-callback
463+
430464
StatusLambdaMethodResource:
431465
Type: AWS::ApiGateway::Resource
432466
Properties:
@@ -516,7 +550,7 @@ Resources:
516550
# if you add a new endpoint, then change the name of this resource
517551
# also need to change it in RestApiGatewayStage.Properties.DeploymentId
518552
# *********************************************************************
519-
RestApiGatewayDeploymentV1f:
553+
RestApiGatewayDeploymentV2f:
520554
Type: AWS::ApiGateway::Deployment
521555
DependsOn:
522556
# see note above if you add something in here when you add a new endpoint
@@ -525,6 +559,7 @@ Resources:
525559
- CapabilityStatementMethod
526560
- Format1UpdatePrescriptionStatusMethod
527561
- CheckPrescriptionStatusUpdatesWaitCondition
562+
- NotificationDeliveryStatusCallbackMethod
528563
# see note above if you add something in here when you add a new endpoint
529564
Properties:
530565
RestApiId: !Ref RestApiGateway
@@ -533,7 +568,7 @@ Resources:
533568
Type: AWS::ApiGateway::Stage
534569
Properties:
535570
RestApiId: !Ref RestApiGateway
536-
DeploymentId: !Ref RestApiGatewayDeploymentV1f
571+
DeploymentId: !Ref RestApiGatewayDeploymentV2f
537572
StageName: prod
538573
TracingEnabled: true
539574
AccessLogSetting:
@@ -557,6 +592,7 @@ Resources:
557592
- - Fn::ImportValue: !Sub ${StackName}:state-machines:${UpdatePrescriptionStatusStateMachineName}:ExecuteStateMachinePolicy
558593
- Fn::ImportValue: !Sub ${StackName}:functions:${StatusFunctionName}:ExecuteLambdaPolicyArn
559594
- Fn::ImportValue: !Sub ${StackName}:functions:${CapabilityStatementFunctionName}:ExecuteLambdaPolicyArn
595+
- Fn::ImportValue: !Sub ${StackName}:functions:${NHSNotifyUpdateCallbackFunctionName}:ExecuteLambdaPolicyArn
560596
- Fn::ImportValue: !Sub ${StackName}:state-machines:${Format1UpdatePrescriptionsStatusStateMachineName}:ExecuteStateMachinePolicy
561597
- !If
562598
- ShouldDeployCheckPrescriptionStatusUpdate

SAMtemplates/functions/lambda_resources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Resources:
8383
- !ImportValue lambda-resources:LambdaInsightsLogGroupPolicy
8484
- !ImportValue account-resources:CloudwatchEncryptionKMSPolicyArn
8585
- !ImportValue account-resources:LambdaDecryptSecretsKMSPolicy
86+
- !ImportValue secrets:GetNotifySecretsManagedPolicy
8687
- !If
8788
- ShouldIncludeAdditionalPolicies
8889
- !Join

SAMtemplates/functions/main.yaml

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ Parameters:
2525
Type: String
2626
Default: none
2727

28-
# PrescriptionNotificationStatesTableName:
29-
# Type: String
30-
# Default: none
28+
PrescriptionNotificationStatesTableName:
29+
Type: String
30+
Default: none
3131

3232
NHSNotifyPrescriptionsSQSQueueUrl:
3333
Type: String
3434
Default: none
3535

36+
SQSSaltSecret:
37+
Type: String
38+
Default: none
39+
3640
EnabledSiteODSCodesParam:
3741
Type: AWS::SSM::Parameter::Value<String>
3842

@@ -41,7 +45,7 @@ Parameters:
4145

4246
BlockedSiteODSCodesParam:
4347
Type: AWS::SSM::Parameter::Value<String>
44-
48+
4549
LogLevel:
4650
Type: String
4751

@@ -69,17 +73,6 @@ Conditions:
6973
- !Ref DeployCheckPrescriptionStatusUpdate
7074

7175
Resources:
72-
SQSSaltSecret:
73-
Type: AWS::SecretsManager::Secret
74-
Properties:
75-
Name: !Sub ${StackName}-SqsSalt
76-
Description: Auto-generated salt for SQS_SALT
77-
GenerateSecretString:
78-
SecretStringTemplate: "{}"
79-
GenerateStringKey: salt
80-
PasswordLength: 32
81-
ExcludePunctuation: true
82-
8376
UpdatePrescriptionStatus:
8477
Type: AWS::Serverless::Function
8578
Properties:
@@ -393,7 +386,7 @@ Resources:
393386
Variables:
394387
LOG_LEVEL: !Ref LogLevel
395388
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
396-
# TABLE_NAME: !Ref PrescriptionNotificationStatesTableName
389+
TABLE_NAME: !Ref PrescriptionNotificationStatesTableName
397390
Events:
398391
ScheduleEvent:
399392
Type: ScheduleV2
@@ -436,9 +429,58 @@ Resources:
436429
- - Fn::ImportValue: !Sub ${StackName}-WriteNHSNotifyPrescriptionsSQSQueuePolicyArn
437430
- Fn::ImportValue: !Sub ${StackName}-ReadNHSNotifyPrescriptionsSQSQueuePolicyArn
438431
- Fn::ImportValue: !Sub ${StackName}-UseNotificationSQSQueueKMSKeyPolicyArn
439-
# - Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableReadPolicyArn
440-
# - Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableWritePolicyArn
441-
# - Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionNotificationStatesKMSKeyPolicyArn
432+
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableReadPolicyArn
433+
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableWritePolicyArn
434+
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionNotificationStatesKMSKeyPolicyArn
435+
436+
NHSNotifyUpdateCallback:
437+
Type: AWS::Serverless::Function
438+
Properties:
439+
FunctionName: !Sub ${StackName}-NHSNotifyUpdateCallback
440+
CodeUri: ../../packages/
441+
Handler: lambdaHandler.handler
442+
Role: !GetAtt NHSNotifyUpdateCallbackResources.Outputs.LambdaRoleArn
443+
Environment:
444+
Variables:
445+
LOG_LEVEL: !Ref LogLevel
446+
TABLE_NAME: !Ref PrescriptionNotificationStatesTableName
447+
APP_NAME_SECRET: secrets-PSU-Notify-Application-Name
448+
API_KEY_SECRET: secrets-PSU-Notify-API-Key
449+
Metadata:
450+
BuildMethod: esbuild
451+
guard:
452+
SuppressedRules:
453+
- LAMBDA_DLQ_CHECK
454+
- LAMBDA_INSIDE_VPC
455+
- LAMBDA_CONCURRENCY_CHECK
456+
BuildProperties:
457+
Minify: true
458+
Target: es2020
459+
Sourcemap: true
460+
tsconfig: nhsNotifyUpdateCallback/tsconfig.json
461+
packages: bundle
462+
EntryPoints:
463+
- nhsNotifyUpdateCallback/src/lambdaHandler.ts
464+
465+
NHSNotifyUpdateCallbackResources:
466+
Type: AWS::Serverless::Application
467+
Properties:
468+
Location: lambda_resources.yaml
469+
Parameters:
470+
StackName: !Ref StackName
471+
LambdaName: !Sub ${StackName}-NHSNotifyUpdateCallback
472+
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-NHSNotifyUpdateCallback
473+
IncludeAdditionalPolicies: true
474+
AdditionalPolicies: !Join
475+
- ","
476+
- - Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableReadPolicyArn
477+
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStatesTableName}:TableWritePolicyArn
478+
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionNotificationStatesKMSKeyPolicyArn
479+
LogRetentionInDays: !Ref LogRetentionInDays
480+
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
481+
EnableSplunk: !Ref EnableSplunk
482+
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
483+
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
442484

443485
Outputs:
444486
UpdatePrescriptionStatusFunctionName:
@@ -506,3 +548,11 @@ Outputs:
506548
NotifyProcessorFunctionArn:
507549
Description: The function ARN of the NHS Notify lambda
508550
Value: !GetAtt NotifyProcessor.Arn
551+
552+
NHSNotifyUpdateCallbackFunctionName:
553+
Description: The function name of the NHSNotifyUpdateCallback lambda
554+
Value: !Ref NHSNotifyUpdateCallback
555+
556+
NHSNotifyUpdateCallbackFunctionArn:
557+
Description: The function ARN of the NHSNotifyUpdateCallback lambda
558+
Value: !GetAtt NHSNotifyUpdateCallback.Arn

SAMtemplates/main_template.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ Parameters:
9090
Type: String
9191

9292
Resources:
93+
Secrets:
94+
Type: AWS::Serverless::Application
95+
Properties:
96+
Location: secrets/main.yaml
97+
Parameters:
98+
StackName: !Ref AWS::StackName
99+
93100
Parameters:
94101
Type: AWS::Serverless::Application
95102
Properties:
@@ -131,6 +138,8 @@ Resources:
131138
CapabilityStatementFunctionArn: !GetAtt Functions.Outputs.CapabilityStatementFunctionArn
132139
CheckPrescriptionStatusUpdatesFunctionName: !GetAtt Functions.Outputs.CheckPrescriptionStatusUpdatesFunctionName
133140
CheckPrescriptionStatusUpdatesFunctionArn: !GetAtt Functions.Outputs.CheckPrescriptionStatusUpdatesFunctionArn
141+
NHSNotifyUpdateCallbackFunctionName: !GetAtt Functions.Outputs.NHSNotifyUpdateCallbackFunctionName
142+
NHSNotifyUpdateCallbackFunctionArn: !GetAtt Functions.Outputs.NHSNotifyUpdateCallbackFunctionArn
134143
LogRetentionInDays: !Ref LogRetentionInDays
135144
EnableSplunk: !Ref EnableSplunk
136145
DeployCheckPrescriptionStatusUpdate: !Ref DeployCheckPrescriptionStatusUpdate
@@ -142,8 +151,9 @@ Resources:
142151
Parameters:
143152
StackName: !Ref AWS::StackName
144153
PrescriptionStatusUpdatesTableName: !GetAtt Tables.Outputs.PrescriptionStatusUpdatesTableName
145-
# PrescriptionNotificationStatesTableName: !GetAtt Tables.Outputs.PrescriptionNotificationStatesTableName
154+
PrescriptionNotificationStatesTableName: !GetAtt Tables.Outputs.PrescriptionNotificationStatesTableName
146155
NHSNotifyPrescriptionsSQSQueueUrl: !GetAtt Messaging.Outputs.NHSNotifyPrescriptionsSQSQueueUrl
156+
SQSSaltSecret: !GetAtt Secrets.Outputs.SQSSaltSecret
147157
EnabledSiteODSCodesParam: !GetAtt Parameters.Outputs.EnabledSiteODSCodesParameterName
148158
EnabledSystemsParam: !GetAtt Parameters.Outputs.EnabledSystemsParameterName
149159
BlockedSiteODSCodesParam: !GetAtt Parameters.Outputs.BlockedSiteODSCodesParameterName

SAMtemplates/parameters/main.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Resources:
5555
Value: !If
5656
- IsProd
5757
- > # Prod notification disabled
58-
A83008
58+
B3J1Z
5959
- > # Non-prod
60-
A83008
60+
B3J1Z
6161
6262
Outputs:
6363
EnabledSiteODSCodesParameterName:

0 commit comments

Comments
 (0)