From 3635fa03ed273ccce41ba1a40355883d56612656 Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Tue, 29 Apr 2025 14:00:58 +0000 Subject: [PATCH 1/5] Update log message to be less confusing. Make status check not case sensitive --- packages/updatePrescriptionStatus/src/utils/sqsClient.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/updatePrescriptionStatus/src/utils/sqsClient.ts b/packages/updatePrescriptionStatus/src/utils/sqsClient.ts index 76b03500b1..8d4d7bb90b 100644 --- a/packages/updatePrescriptionStatus/src/utils/sqsClient.ts +++ b/packages/updatePrescriptionStatus/src/utils/sqsClient.ts @@ -27,7 +27,7 @@ function chunkArray(arr: Array, size: number): Array> { * @param logger - Logger instance */ export async function pushPrescriptionToNotificationSQS(requestId: string, data: Array, logger: Logger) { - logger.info("Pushing data items up to the notifications SQS", {count: data.length, sqsUrl}) + logger.info("Checking if any items require notifications", {numItemsToBeChecked: data.length, sqsUrl}) if (!sqsUrl) { logger.error("Notifications SQS URL not found in environment variables") @@ -45,7 +45,7 @@ export async function pushPrescriptionToNotificationSQS(requestId: string, data: for (const batch of batches) { const entries = batch - .filter((item) => updateStatuses.includes(item.Status)) + .filter((item) => updateStatuses.includes(item.Status.toLowerCase())) // Add the request ID to the SQS message .map((item) => ({...item, requestId})) .map((item) => ({Id: v4().toUpperCase(), MessageBody: JSON.stringify(item)})) @@ -62,7 +62,7 @@ export async function pushPrescriptionToNotificationSQS(requestId: string, data: const messageIds = entries.map((el) => el.Id) logger.info( - "Notification required. Pushing prescriptions with the following SQS message IDs", + "Notification required. Pushing prescriptions to the notifications SQS with the following SQS message IDs", {messageIds, requestId} ) From 754e11d99a6feff95498d5d6a6f491742b959e6a Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Tue, 29 Apr 2025 14:08:11 +0000 Subject: [PATCH 2/5] Rename lambda --- SAMtemplates/functions/main.yaml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/SAMtemplates/functions/main.yaml b/SAMtemplates/functions/main.yaml index 53282d8146..b9c5bdf74b 100644 --- a/SAMtemplates/functions/main.yaml +++ b/SAMtemplates/functions/main.yaml @@ -331,7 +331,7 @@ Resources: SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream - NHSNotifyLambdaScheduleEventRole: + EPSNotifyProcessorScheduleEventRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: @@ -344,9 +344,9 @@ Resources: Action: - sts:AssumeRole ManagedPolicyArns: - - !Ref NHSNotifyLambdaScheduleEventRolePolicy + - !Ref EPSNotifyProcessorScheduleEventRolePolicy - NHSNotifyLambdaScheduleEventRolePolicy: + EPSNotifyProcessorScheduleEventRolePolicy: Type: AWS::IAM::ManagedPolicy Properties: PolicyDocument: @@ -356,15 +356,15 @@ Resources: Action: - lambda:InvokeFunction Resource: - - !GetAtt NHSNotifyLambda.Arn + - !GetAtt EPSNotifyProcessor.Arn - NHSNotifyLambda: + EPSNotifyProcessor: Type: AWS::Serverless::Function Properties: - FunctionName: !Sub ${StackName}-NHSNotifyLambda + FunctionName: !Sub ${StackName}-EPSNotifyProcessor CodeUri: ../../packages/ Handler: nhsNotifyLambda.handler - Role: !GetAtt NHSNotifyLambdaResources.Outputs.LambdaRoleArn + Role: !GetAtt EPSNotifyProcessorResources.Outputs.LambdaRoleArn Environment: Variables: LOG_LEVEL: !Ref LogLevel @@ -376,7 +376,7 @@ Resources: Properties: Name: !Sub ${StackName}-NHSNotifySchedule ScheduleExpression: "rate(1 minute)" - RoleArn: !GetAtt NHSNotifyLambdaScheduleEventRole.Arn + RoleArn: !GetAtt EPSNotifyProcessorScheduleEventRole.Arn Metadata: BuildMethod: esbuild guard: @@ -393,14 +393,14 @@ Resources: EntryPoints: - nhsNotifyLambda/src/nhsNotifyLambda.ts - NHSNotifyLambdaResources: + EPSNotifyProcessorResources: 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 + LambdaName: !Sub ${StackName}-EPSNotifyProcessor + LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-EPSNotifyProcessor LogRetentionInDays: !Ref LogRetentionInDays CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn EnableSplunk: !Ref EnableSplunk @@ -475,10 +475,10 @@ Outputs: - !GetAtt CheckPrescriptionStatusUpdates.Arn - "" - NHSNotifyLambdaFunctionName: + EPSNotifyProcessorFunctionName: Description: The function name of the NHS Notify lambda - Value: !Ref NHSNotifyLambda + Value: !Ref EPSNotifyProcessor - NHSNotifyLambdaFunctionArn: + EPSNotifyProcessorFunctionArn: Description: The function ARN of the NHS Notify lambda - Value: !GetAtt NHSNotifyLambda.Arn + Value: !GetAtt EPSNotifyProcessor.Arn From d9adfcbdf5ad76097c9dc0b8a756a416d18c04fd Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Tue, 29 Apr 2025 14:10:47 +0000 Subject: [PATCH 3/5] Rename lambda --- SAMtemplates/functions/main.yaml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/SAMtemplates/functions/main.yaml b/SAMtemplates/functions/main.yaml index b9c5bdf74b..d0dd42bb1e 100644 --- a/SAMtemplates/functions/main.yaml +++ b/SAMtemplates/functions/main.yaml @@ -331,7 +331,7 @@ Resources: SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream - EPSNotifyProcessorScheduleEventRole: + PSUNotifyProcessorScheduleEventRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: @@ -344,9 +344,9 @@ Resources: Action: - sts:AssumeRole ManagedPolicyArns: - - !Ref EPSNotifyProcessorScheduleEventRolePolicy + - !Ref PSUNotifyProcessorScheduleEventRolePolicy - EPSNotifyProcessorScheduleEventRolePolicy: + PSUNotifyProcessorScheduleEventRolePolicy: Type: AWS::IAM::ManagedPolicy Properties: PolicyDocument: @@ -356,15 +356,15 @@ Resources: Action: - lambda:InvokeFunction Resource: - - !GetAtt EPSNotifyProcessor.Arn + - !GetAtt PSUNotifyProcessor.Arn - EPSNotifyProcessor: + PSUNotifyProcessor: Type: AWS::Serverless::Function Properties: - FunctionName: !Sub ${StackName}-EPSNotifyProcessor + FunctionName: !Sub ${StackName}-PSUNotifyProcessor CodeUri: ../../packages/ Handler: nhsNotifyLambda.handler - Role: !GetAtt EPSNotifyProcessorResources.Outputs.LambdaRoleArn + Role: !GetAtt PSUNotifyProcessorResources.Outputs.LambdaRoleArn Environment: Variables: LOG_LEVEL: !Ref LogLevel @@ -376,7 +376,7 @@ Resources: Properties: Name: !Sub ${StackName}-NHSNotifySchedule ScheduleExpression: "rate(1 minute)" - RoleArn: !GetAtt EPSNotifyProcessorScheduleEventRole.Arn + RoleArn: !GetAtt PSUNotifyProcessorScheduleEventRole.Arn Metadata: BuildMethod: esbuild guard: @@ -393,14 +393,14 @@ Resources: EntryPoints: - nhsNotifyLambda/src/nhsNotifyLambda.ts - EPSNotifyProcessorResources: + PSUNotifyProcessorResources: Type: AWS::Serverless::Application Properties: Location: lambda_resources.yaml Parameters: StackName: !Ref StackName - LambdaName: !Sub ${StackName}-EPSNotifyProcessor - LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-EPSNotifyProcessor + LambdaName: !Sub ${StackName}-PSUNotifyProcessor + LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-PSUNotifyProcessor LogRetentionInDays: !Ref LogRetentionInDays CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn EnableSplunk: !Ref EnableSplunk @@ -475,10 +475,10 @@ Outputs: - !GetAtt CheckPrescriptionStatusUpdates.Arn - "" - EPSNotifyProcessorFunctionName: + PSUNotifyProcessorFunctionName: Description: The function name of the NHS Notify lambda - Value: !Ref EPSNotifyProcessor + Value: !Ref PSUNotifyProcessor - EPSNotifyProcessorFunctionArn: + PSUNotifyProcessorFunctionArn: Description: The function ARN of the NHS Notify lambda - Value: !GetAtt EPSNotifyProcessor.Arn + Value: !GetAtt PSUNotifyProcessor.Arn From c48a98f1e63e1fbdd4edb26e60041e662720a509 Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Tue, 29 Apr 2025 14:12:55 +0000 Subject: [PATCH 4/5] Rename lambda --- SAMtemplates/functions/main.yaml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/SAMtemplates/functions/main.yaml b/SAMtemplates/functions/main.yaml index d0dd42bb1e..5f8c362255 100644 --- a/SAMtemplates/functions/main.yaml +++ b/SAMtemplates/functions/main.yaml @@ -331,7 +331,7 @@ Resources: SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream - PSUNotifyProcessorScheduleEventRole: + NotifyProcessorScheduleEventRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: @@ -344,9 +344,9 @@ Resources: Action: - sts:AssumeRole ManagedPolicyArns: - - !Ref PSUNotifyProcessorScheduleEventRolePolicy + - !Ref NotifyProcessorScheduleEventRolePolicy - PSUNotifyProcessorScheduleEventRolePolicy: + NotifyProcessorScheduleEventRolePolicy: Type: AWS::IAM::ManagedPolicy Properties: PolicyDocument: @@ -356,15 +356,15 @@ Resources: Action: - lambda:InvokeFunction Resource: - - !GetAtt PSUNotifyProcessor.Arn + - !GetAtt NotifyProcessor.Arn - PSUNotifyProcessor: + NotifyProcessor: Type: AWS::Serverless::Function Properties: - FunctionName: !Sub ${StackName}-PSUNotifyProcessor + FunctionName: !Sub ${StackName}-NotifyProcessor CodeUri: ../../packages/ Handler: nhsNotifyLambda.handler - Role: !GetAtt PSUNotifyProcessorResources.Outputs.LambdaRoleArn + Role: !GetAtt NotifyProcessorResources.Outputs.LambdaRoleArn Environment: Variables: LOG_LEVEL: !Ref LogLevel @@ -376,7 +376,7 @@ Resources: Properties: Name: !Sub ${StackName}-NHSNotifySchedule ScheduleExpression: "rate(1 minute)" - RoleArn: !GetAtt PSUNotifyProcessorScheduleEventRole.Arn + RoleArn: !GetAtt NotifyProcessorScheduleEventRole.Arn Metadata: BuildMethod: esbuild guard: @@ -393,14 +393,14 @@ Resources: EntryPoints: - nhsNotifyLambda/src/nhsNotifyLambda.ts - PSUNotifyProcessorResources: + NotifyProcessorResources: Type: AWS::Serverless::Application Properties: Location: lambda_resources.yaml Parameters: StackName: !Ref StackName - LambdaName: !Sub ${StackName}-PSUNotifyProcessor - LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-PSUNotifyProcessor + 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 @@ -475,10 +475,10 @@ Outputs: - !GetAtt CheckPrescriptionStatusUpdates.Arn - "" - PSUNotifyProcessorFunctionName: + NotifyProcessorFunctionName: Description: The function name of the NHS Notify lambda - Value: !Ref PSUNotifyProcessor + Value: !Ref NotifyProcessor - PSUNotifyProcessorFunctionArn: + NotifyProcessorFunctionArn: Description: The function ARN of the NHS Notify lambda - Value: !GetAtt PSUNotifyProcessor.Arn + Value: !GetAtt NotifyProcessor.Arn From 8510217a18cdd53d308f0422d918db81d09c4212 Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Tue, 29 Apr 2025 14:20:04 +0000 Subject: [PATCH 5/5] Update tests --- .../updatePrescriptionStatus/tests/testSqsClient.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/updatePrescriptionStatus/tests/testSqsClient.test.ts b/packages/updatePrescriptionStatus/tests/testSqsClient.test.ts index b841c3e010..bc9065dbfb 100644 --- a/packages/updatePrescriptionStatus/tests/testSqsClient.test.ts +++ b/packages/updatePrescriptionStatus/tests/testSqsClient.test.ts @@ -63,8 +63,8 @@ describe("Unit tests for pushPrescriptionToNotificationSQS", () => { // It logs the initial push attempt, but never actually sends expect(infoSpy).toHaveBeenCalledWith( - "Pushing data items up to the notifications SQS", - {count: data.length, sqsUrl: process.env.NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL} + "Checking if any items require notifications", + {numItemsToBeChecked: data.length, sqsUrl: process.env.NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL} ) expect(mockSend).not.toHaveBeenCalled() }) @@ -87,7 +87,7 @@ describe("Unit tests for pushPrescriptionToNotificationSQS", () => { // Confirm it logged the "notification required" and the success expect(infoSpy).toHaveBeenCalledWith( - "Notification required. Pushing prescriptions with the following SQS message IDs", + "Notification required. Pushing prescriptions to the notifications SQS with the following SQS message IDs", expect.objectContaining({requestId: "req-789", messageIds: expect.any(Array)}) ) expect(infoSpy).toHaveBeenCalledWith(