Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
76085aa
Add a notifications table definition. PK prescription ID, GSI NHS number
wildjames Apr 15, 2025
2a6a99c
Make capitalisation consistent
wildjames Apr 15, 2025
b26a0e9
Create a blank notifications lambda. Doesn't have a deployment defini…
wildjames Apr 15, 2025
36fda3d
Add nhs notify lambda to main lambda SAM template
wildjames Apr 15, 2025
5787256
Add scheduler, and update lambda handler
wildjames Apr 15, 2025
0e44d81
Merge branch 'main' into aea-5199-setup-notifications-lambda
wildjames Apr 15, 2025
a4e2c9a
Trigger PR title check again
wildjames Apr 15, 2025
6e645fa
Add mock event bridge type. Update dummy unit test
wildjames Apr 15, 2025
186ffef
Merge branch 'main' into aea-5199-setup-notifications-lambda
wildjames Apr 15, 2025
f9f3391
Refactor to not need permissions, mirroring cert checker lambda
wildjames Apr 15, 2025
61c72dc
Merge branch 'aea-5199-setup-notifications-lambda' of github.com:NHSD…
wildjames Apr 15, 2025
586aa34
typo in the version
wildjames Apr 16, 2025
ef9750d
Fix indentation
wildjames Apr 16, 2025
6c4bf0a
whitespace changes
wildjames Apr 16, 2025
2112fc2
using the wrong handler function
wildjames Apr 16, 2025
771de6d
Add SQS queue definition
wildjames Apr 16, 2025
6d5cfbe
Add messaging stack to main yaml
wildjames Apr 16, 2025
fba51c8
Fix import
wildjames Apr 16, 2025
1bffcb3
Retention period too long :(
wildjames Apr 16, 2025
be5e9d9
Empty function in PSU that will push data to SQS
wildjames Apr 16, 2025
f1a154d
Tests seembroken, but wrote an sqs client
wildjames Apr 16, 2025
b994b2b
fix test
wildjames Apr 17, 2025
d526e61
Add send message policy to the update prescription lambda
wildjames Apr 17, 2025
efbc621
Reset env between tests
wildjames Apr 17, 2025
ddbe840
Is it case sensitive?
wildjames Apr 17, 2025
328e1e0
Move permission definition
wildjames Apr 17, 2025
1cec26a
Merge branch 'main' into aea-5199-setup-notifications-lambda
wildjames Apr 17, 2025
f6c7829
add SQS policy to the nofity lambda
wildjames Apr 17, 2025
d4ac39a
Fix typo!
wildjames Apr 17, 2025
4b79e32
Forgot to specify arn export. Also, use stackname parameter
wildjames Apr 17, 2025
aa3ca5a
Nope, dont need the .Arn
wildjames Apr 17, 2025
544238a
Permissions for dealing with our customer-managed KMS
wildjames Apr 22, 2025
ff7be05
Add logic to catch failures of SQS
wildjames Apr 22, 2025
83de1b2
Log the message IDs that are getting pushed when debug is enabled
wildjames Apr 22, 2025
d0bd55b
Add missing permissions
wildjames Apr 22, 2025
367ee4d
Trigger build
wildjames Apr 22, 2025
e129789
Merge branch 'main' into aea-5199-setup-notifications-lambda
wildjames Apr 22, 2025
9261f45
Use a dedicated KMS - permissions are being difficult
wildjames Apr 22, 2025
6dc7c61
Forgot to add a policy
wildjames Apr 22, 2025
7a8b4e5
Merge branch 'main' into aea-5199-setup-notifications-lambda
wildjames Apr 22, 2025
7bfc023
Skip quality checks
wildjames Apr 22, 2025
b56af03
Merge branch 'aea-5199-setup-notifications-lambda' of github.com:NHSD…
wildjames Apr 22, 2025
d6d58cc
Make the notify lambda pull messages from SQS, and log them
wildjames Apr 22, 2025
8216f25
Update log message
wildjames Apr 22, 2025
6a2d224
Set up the consumer to be able to communicate with the table. Alos lo…
wildjames Apr 22, 2025
77821bc
Pass in static table name as a parameter
wildjames Apr 22, 2025
7c91533
Merge branch 'main' into aea-5199-setup-notifications-lambda
wildjames Apr 22, 2025
e39958a
Expand test coverage
wildjames Apr 22, 2025
61a897e
Merge branch 'aea-5199-setup-notifications-lambda' of github.com:NHSD…
wildjames Apr 22, 2025
adb055f
Minimal nhsnotifylambda dynamo unit test
wildjames Apr 23, 2025
804c06b
Expand test coverage
wildjames Apr 23, 2025
eb78c25
Start tests for the drainQueue functiton
wildjames Apr 23, 2025
35d8a92
Expand test coverage
wildjames Apr 23, 2025
9a55102
Merge branch 'main' into aea-5199-setup-notifications-lambda
wildjames Apr 23, 2025
ea0c3fe
Make a more official test for the handler
wildjames Apr 23, 2025
5da248d
Expand test coverage
wildjames Apr 23, 2025
90ccd53
Update type
wildjames Apr 23, 2025
338a135
Address some sonar things
wildjames Apr 23, 2025
17d6566
Move dataitem to a common types package
wildjames Apr 23, 2025
f27d70f
Minor tweaks from self-review
wildjames Apr 23, 2025
6a77bde
Update log message
wildjames Apr 24, 2025
53abd70
Update tests to reflect logging change
wildjames Apr 24, 2025
15ba4d2
Correctly grab request ID
wildjames Apr 24, 2025
501a5fd
Merge branch 'main' into aea-5199-setup-notifications-lambda
wildjames Apr 24, 2025
dd81780
Update log
wildjames Apr 24, 2025
00178b2
Remove log messages
wildjames Apr 24, 2025
7fd8396
lengthen visibility timeout
wildjames Apr 24, 2025
21cf5f0
Resolve package lock conflict
wildjames Apr 28, 2025
6b9dcbc
Resolve package lock conflict
wildjames Apr 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ repos:
files: ^packages\/checkPrescriptionStatusUpdates
types_or: [ts, tsx, javascript, jsx, json]
pass_filenames: false

- id: lint-nhsNotifyLambda
name: Lint nhsNotifyLambda
entry: npm
args:
["run", "--prefix=packages/nhsNotifyLambda", "lint"]
language: system
files: ^packages\/nhsNotifyLambda
types_or: [ts, tsx, javascript, jsx, json]
pass_filenames: false

- id: lint-commonTesting
name: Lint common/testing
Expand Down
8 changes: 8 additions & 0 deletions .vscode/eps-prescription-status-update-api.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"name": "packages/cpsuLambda",
"path": "../packages/cpsuLambda"
},
{
"name": "packages/nhsNotifyLambda",
"path": "../packages/nhsNotifyLambda"
},
{
"name": "packages/capabilityStatement",
"path": "../packages/capabilityStatement"
Expand All @@ -36,6 +40,10 @@
"name": "packages/checkPrescriptionStatusUpdates",
"path": "../packages/checkPrescriptionStatusUpdates"
},
{
"name": "packages/common/commonTypes",
"path": "../packages/common/commonTypes"
},
{
"name": "packages/common/testing",
"path": "../packages/common/testing"
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ lint-node: compile-node
npm run lint --workspace packages/capabilityStatement
npm run lint --workspace packages/cpsuLambda
npm run lint --workspace packages/checkPrescriptionStatusUpdates
npm run lint --workspace packages/nhsNotifyLambda
npm run lint --workspace packages/common/testing
npm run lint --workspace packages/common/middyErrorHandler
npm run lint --workspace packages/common/commonTypes

lint-specification: compile-specification
npm run lint --workspace packages/specification
Expand All @@ -144,6 +146,7 @@ test: compile
npm run test --workspace packages/capabilityStatement
npm run test --workspace packages/cpsuLambda
npm run test --workspace packages/checkPrescriptionStatusUpdates
npm run test --workspace packages/nhsNotifyLambda
npm run test --workspace packages/common/middyErrorHandler

clean:
Expand All @@ -159,9 +162,12 @@ clean:
rm -rf packages/capabilityStatement/lib
rm -rf packages/cpsuLambda/coverage
rm -rf packages/cpsuLambda/lib
rm -rf packages/nhsNotifyLambda/coverage
rm -rf packages/nhsNotifyLambda/lib
rm -rf packages/checkPrescriptionStatusUpdates/lib
rm -rf packages/common/testing/lib
rm -rf packages/common/middyErrorHandler/lib
rm -rf packages/common/commonTypes/lib
rm -rf .aws-sam

deep-clean: clean
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This is the AWS layer that provides an API for EPS Prescription Status Update.
- `packages/statusLambda/` Returns the status of the updatePrescriptionStatus endpoint
- `packages/capabilityStatement/` Returns a static capability statement.
- `packages/cpsuLambda` Handles updating prescription status using a custom format.
- `packages/nhsNotifyLambda` Handles sending prescription notifications to the NHS notify service.
- `scripts/` Utilities helpful to developers of this specification.
- `postman/` Postman collections to call the APIs. Documentation on how to use them are in the collections.
- `SAMtemplates/` Contains the SAM templates used to define the stacks.
Expand Down
104 changes: 104 additions & 0 deletions SAMtemplates/functions/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ Parameters:
Type: String
Default: none

PrescriptionNotificationStateTableName:
Type: String
Default: none

NHSNotifyPrescriptionsSQSQueueUrl:
Type: String
Default: none

LogLevel:
Type: String

Expand Down Expand Up @@ -62,6 +70,7 @@ Resources:
Environment:
Variables:
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
LOG_LEVEL: !Ref LogLevel
ENVIRONMENT: !Ref Environment
TEST_PRESCRIPTIONS_1: "None"
Expand Down Expand Up @@ -96,6 +105,8 @@ Resources:
- - 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
LogRetentionInDays: !Ref LogRetentionInDays
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
EnableSplunk: !Ref EnableSplunk
Expand Down Expand Up @@ -320,6 +331,91 @@ Resources:
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream

NHSNotifyLambdaScheduleEventRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- scheduler.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- !Ref NHSNotifyLambdaScheduleEventRolePolicy

NHSNotifyLambdaScheduleEventRolePolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !GetAtt NHSNotifyLambda.Arn

NHSNotifyLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${StackName}-NHSNotifyLambda
CodeUri: ../../packages/
Handler: nhsNotifyLambda.handler
Role: !GetAtt NHSNotifyLambdaResources.Outputs.LambdaRoleArn
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
TABLE_NAME: !Ref PrescriptionNotificationStateTableName
Events:
ScheduleEvent:
Type: ScheduleV2
Properties:
Name: !Sub ${StackName}-NHSNotifySchedule
ScheduleExpression: "rate(1 minute)"
RoleArn: !GetAtt NHSNotifyLambdaScheduleEventRole.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

NHSNotifyLambdaResources:
Type: AWS::Serverless::Application
Properties:
Location: lambda_resources.yaml
Parameters:
StackName: !Ref StackName
LambdaName: !Sub ${StackName}-NHSNotifyLambda
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-NHSNotifyLambda
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:${PrescriptionNotificationStateTableName}:TableReadPolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionNotificationStateTableName}:TableWritePolicyArn
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionNotificationStateKMSKeyPolicyArn

Outputs:
UpdatePrescriptionStatusFunctionName:
Description: The function name of the UpdatePrescriptionStatus lambda
Expand Down Expand Up @@ -378,3 +474,11 @@ Outputs:
- ShouldDeployCheckPrescriptionStatusUpdate
- !GetAtt CheckPrescriptionStatusUpdates.Arn
- ""

NHSNotifyLambdaFunctionName:
Description: The function name of the NHS Notify lambda
Value: !Ref NHSNotifyLambda

NHSNotifyLambdaFunctionArn:
Description: The function ARN of the NHS Notify lambda
Value: !GetAtt NHSNotifyLambda.Arn
9 changes: 9 additions & 0 deletions SAMtemplates/main_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ Resources:
StackName: !Ref AWS::StackName
EnableDynamoDBAutoScaling: !Ref EnableDynamoDBAutoScaling

Messaging:
Type: AWS::Serverless::Application
Properties:
Location: messaging/main.yaml
Parameters:
StackName: !Ref AWS::StackName

Apis:
Type: AWS::Serverless::Application
Properties:
Expand Down Expand Up @@ -127,6 +134,8 @@ Resources:
Parameters:
StackName: !Ref AWS::StackName
PrescriptionStatusUpdatesTableName: !GetAtt Tables.Outputs.PrescriptionStatusUpdatesTableName
PrescriptionNotificationStateTableName: !GetAtt Tables.Outputs.PrescriptionNotificationStateTableName
NHSNotifyPrescriptionsSQSQueueUrl: !GetAtt Messaging.Outputs.NHSNotifyPrescriptionsSQSQueueUrl
LogLevel: !Ref LogLevel
LogRetentionInDays: !Ref LogRetentionInDays
EnableSplunk: !Ref EnableSplunk
Expand Down
129 changes: 129 additions & 0 deletions SAMtemplates/messaging/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: |
SQS messaging stacks used by the PSU

Parameters:
StackName:
Type: String

Resources:
NotificationSQSQueueKMSKey:
Type: AWS::KMS::Key
Properties:
EnableKeyRotation: true
KeyPolicy:
Version: 2012-10-17
Id: NotificationSQSQueueKeyPolicy
Statement:
- Sid: EnableIAMUserPermissions
Effect: Allow
Principal:
AWS: !Sub "arn:aws:iam::${AWS::AccountId}:root"
Action: kms:*
Resource: "*"

NotificationSQSQueueKMSKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: !Sub alias/${StackName}-NotificationSQSQueueKMSKey
TargetKeyId: !Ref NotificationSQSQueueKMSKey

UseNotificationSQSQueueKMSKeyPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: !Sub ${StackName}-UseNotificationSQSQueueKMSKey
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: AllowKmsForSqsEncryption
Effect: Allow
Action:
- kms:DescribeKey
- kms:GenerateDataKey*
- kms:Encrypt
- kms:Decrypt
Resource: !GetAtt NotificationSQSQueueKMSKey.Arn

NHSNotifyPrescriptionsSQSQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: !Sub ${StackName}-NHSNotifyPrescriptions
KmsMasterKeyId: !Ref NotificationSQSQueueKMSKeyAlias
MessageRetentionPeriod: 86400 # 1 day in seconds
RedrivePolicy:
deadLetterTargetArn: !GetAtt NHSNotifyPrescriptionsDeadLetterQueue.Arn
maxReceiveCount: 5
VisibilityTimeout: 300

NHSNotifyPrescriptionsDeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: !Sub ${StackName}-NHSNotifyPrescriptionsDeadLetter
KmsMasterKeyId: !Ref NotificationSQSQueueKMSKeyAlias
MessageRetentionPeriod: 604800 # 1 week in seconds
VisibilityTimeout: 300

ReadNHSNotifyPrescriptionsSQSQueuePolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- sqs:ReceiveMessage
- sqs:DeleteMessage
- sqs:ChangeMessageVisibility
- sqs:GetQueueAttributes
- sqs:GetQueueUrl
- kms:GenerateDataKey
- kms:Decrypt
Resource: !GetAtt NHSNotifyPrescriptionsSQSQueue.Arn

WriteNHSNotifyPrescriptionsSQSQueuePolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: !Sub ${StackName}-NHSNotifyPrescriptionsSendMessagePolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- sqs:SendMessage
- sqs:SendMessageBatch
- sqs:GetQueueUrl
- kms:GenerateDataKey
- kms:Decrypt
Resource: !GetAtt NHSNotifyPrescriptionsSQSQueue.Arn

Outputs:
NHSNotifyPrescriptionsSQSQueueUrl:
Description: The URL of the NHS Notify Prescriptions SQS Queue
Value: !Ref NHSNotifyPrescriptionsSQSQueue
Export:
Name: !Sub ${StackName}-NHSNotifyPrescriptionsSQSQueueUrl

NHSNotifyPrescriptionsSQSQueueArn:
Description: The ARN of the NHS Notify Prescriptions SQS Queue
Value: !GetAtt NHSNotifyPrescriptionsSQSQueue.Arn
Export:
Name: !Sub ${StackName}-NHSNotifyPrescriptionsSQSQueueArn

ReadNHSNotifyPrescriptionsSQSQueuePolicyArn:
Description: ARN of policy granting permission to read the prescriptions queue
Value: !Ref ReadNHSNotifyPrescriptionsSQSQueuePolicy
Export:
Name: !Sub ${StackName}-ReadNHSNotifyPrescriptionsSQSQueuePolicyArn

WriteNHSNotifyPrescriptionsSQSQueuePolicyArn:
Description: ARN of policy granting permission to write to the prescriptions queue
Value: !Ref WriteNHSNotifyPrescriptionsSQSQueuePolicy
Export:
Name: !Sub ${StackName}-WriteNHSNotifyPrescriptionsSQSQueuePolicyArn

UseNotificationSQSQueueKMSKeyPolicyArn:
Description: ARN of managed policy granting prescriptions queue KMS usage
Value: !Ref UseNotificationSQSQueueKMSKeyPolicy
Export:
Name: !Sub ${StackName}-UseNotificationSQSQueueKMSKeyPolicyArn
Loading