Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions .vscode/eps-prescription-status-update-api.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"name": "packages/nhsNotifyLambda",
"path": "../packages/nhsNotifyLambda"
},
{
"name": "packages/postDatedLambda",
"path": "../packages/postDatedLambda"
},
{
"name": "packages/nhsNotifyUpdateCallback",
"path": "../packages/nhsNotifyUpdateCallback"
Expand Down Expand Up @@ -152,8 +156,14 @@
"versionable",
"whens"
],
"cSpell.dictionaries": ["en-GB"],
"cSpell.ignorePaths": ["package-lock.json", "node_modules", ".vscode"],
"cSpell.dictionaries": [
"en-GB"
],
"cSpell.ignorePaths": [
"package-lock.json",
"node_modules",
".vscode"
],
"jest.jestCommandLine": "NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest --no-cache",
"jest.nodeEnv": {
"POWERTOOLS_DEV": true
Expand Down
108 changes: 108 additions & 0 deletions SAMtemplates/functions/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Parameters:
Type: String
Default: none

PostDatedNotificationsSQSQueueUrl:
Type: String
Default: none

SQSSaltSecret:
Type: AWS::SecretsManager::Secret::Name<String>

Expand Down Expand Up @@ -121,6 +125,7 @@ Resources:
Variables:
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
POST_DATED_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref PostDatedNotificationsSQSQueueUrl
SQS_SALT: !Ref SQSSaltSecret
ENABLED_SITE_ODS_CODES_PARAM: !Ref EnabledSiteODSCodesParam
ENABLED_SYSTEMS_PARAM: !Ref EnabledSystemsParam
Expand Down Expand Up @@ -165,6 +170,7 @@ Resources:
- 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
Expand Down Expand Up @@ -443,6 +449,99 @@ Resources:
Events:
ScheduleEvent:
Type: ScheduleV2

## 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(2 minutes)" # TODO: Increase to 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

Properties:
Name: !Sub ${StackName}-NotifySchedule
ScheduleExpression: "rate(1 minute)"
Expand Down Expand Up @@ -719,3 +818,12 @@ Outputs:
NHSNotifyUpdateCallbackFunctionArn:
Description: The function ARN of the NHSNotifyUpdateCallback lambda
Value: !GetAtt NHSNotifyUpdateCallback.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
1 change: 1 addition & 0 deletions SAMtemplates/main_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ Resources:
PrescriptionStatusUpdatesTableName: !GetAtt Tables.Outputs.PrescriptionStatusUpdatesTableName
PrescriptionNotificationStatesTableName: !GetAtt Tables.Outputs.PrescriptionNotificationStatesTableName
NHSNotifyPrescriptionsSQSQueueUrl: !GetAtt Messaging.Outputs.NHSNotifyPrescriptionsSQSQueueUrl
PostDatedNotificationsSQSQueueUrl: !GetAtt Messaging.Outputs.PostDatedNotificationsSQSQueueUrl
SQSSaltSecret: !GetAtt Secrets.Outputs.SQSSaltSecret
EnabledSiteODSCodesParam: !GetAtt Parameters.Outputs.EnabledSiteODSCodesParameterName
EnabledSystemsParam: !GetAtt Parameters.Outputs.EnabledSystemsParameterName
Expand Down
91 changes: 91 additions & 0 deletions SAMtemplates/messaging/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,65 @@ Resources:
- kms:Decrypt
Resource: !GetAtt NHSNotifyPrescriptionsSQSQueue.Arn

## Post-dated SQS queue starts here
PostDatedNotificationsSQSQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: !Sub ${StackName}-PostDatedNotifications.fifo
FifoQueue: true
ContentBasedDeduplication: false
KmsMasterKeyId: !Ref NotificationSQSQueueKMSKeyAlias
MessageRetentionPeriod: 86400 # 1 day in seconds
RedrivePolicy:
deadLetterTargetArn: !GetAtt PostDatedNotificationsDeadLetterQueue.Arn
maxReceiveCount: 246 # processed every 6 hours for 41 days.
VisibilityTimeout: 300

PostDatedNotificationsDeadLetterQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: !Sub ${StackName}-PostDatedNotificationsDeadLetter.fifo
FifoQueue: true
ContentBasedDeduplication: false
KmsMasterKeyId: !Ref NotificationSQSQueueKMSKeyAlias
MessageRetentionPeriod: 604800 # 1 week in seconds
VisibilityTimeout: 300

ReadPostDatedNotificationsSQSQueuePolicy:
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 PostDatedNotificationsSQSQueue.Arn

WritePostDatedNotificationsSQSQueuePolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: !Sub ${StackName}-PostDatedNotificationsSendMessagePolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- sqs:SendMessage
- sqs:SendMessageBatch
- sqs:DeleteMessage
- sqs:GetQueueUrl
- kms:GenerateDataKey
- kms:Decrypt
Resource: !GetAtt PostDatedNotificationsSQSQueue.Arn
# End of post-dated stuff

Outputs:
NHSNotifyPrescriptionsSQSQueueUrl:
Description: The URL of the NHS Notify Prescriptions SQS Queue
Expand Down Expand Up @@ -138,3 +197,35 @@ Outputs:
Value: !Ref UseNotificationSQSQueueKMSKeyPolicy
Export:
Name: !Sub ${StackName}-UseNotificationSQSQueueKMSKeyPolicyArn

# Post dated SQS outputs start here
PostDatedNotificationsSQSQueueUrl:
Description: The URL of the Post Dated Notifications SQS Queue
Value: !Ref PostDatedNotificationsSQSQueue
Export:
Name: !Sub ${StackName}-PostDatedNotificationsSQSQueueUrl

PostDatedNotificationsSQSQueueArn:
Description: The ARN of the Post Dated Notifications SQS Queue
Value: !GetAtt PostDatedNotificationsSQSQueue.Arn
Export:
Name: !Sub ${StackName}-PostDatedNotificationsSQSQueueArn

PostDatedNotificationsDeadLetterQueueArn:
Description: The ARN of the Post Dated Notifications Dead Letter Queue
Value: !GetAtt PostDatedNotificationsDeadLetterQueue.Arn
Export:
Name: !Sub ${StackName}-PostDatedNotificationsDeadLetterQueueArn

ReadPostDatedNotificationsSQSQueuePolicyArn:
Description: ARN of policy granting permission to read the post dated notifications queue
Value: !Ref ReadPostDatedNotificationsSQSQueuePolicy
Export:
Name: !Sub ${StackName}-ReadPostDatedNotificationsSQSQueuePolicyArn

WritePostDatedNotificationsSQSQueuePolicyArn:
Description: ARN of policy granting permission to write to the post dated notifications queue
Value: !Ref WritePostDatedNotificationsSQSQueuePolicy
Export:
Name: !Sub ${StackName}-WritePostDatedNotificationsSQSQueuePolicyArn
# End
Loading
Loading