diff --git a/SAMtemplates/functions/main.yaml b/SAMtemplates/functions/main.yaml index 2578782700..949ff31753 100644 --- a/SAMtemplates/functions/main.yaml +++ b/SAMtemplates/functions/main.yaml @@ -343,7 +343,7 @@ Resources: SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream - NHSNotifyLambdaScheduleEventRole: + NotifyProcessorScheduleEventRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: @@ -356,9 +356,9 @@ Resources: Action: - sts:AssumeRole ManagedPolicyArns: - - !Ref NHSNotifyLambdaScheduleEventRolePolicy + - !Ref NotifyProcessorScheduleEventRolePolicy - NHSNotifyLambdaScheduleEventRolePolicy: + NotifyProcessorScheduleEventRolePolicy: Type: AWS::IAM::ManagedPolicy Properties: PolicyDocument: @@ -368,15 +368,15 @@ Resources: Action: - lambda:InvokeFunction Resource: - - !GetAtt NHSNotifyLambda.Arn + - !GetAtt NotifyProcessor.Arn - NHSNotifyLambda: + NotifyProcessor: Type: AWS::Serverless::Function Properties: - FunctionName: !Sub ${StackName}-NHSNotifyLambda + FunctionName: !Sub ${StackName}-NotifyProcessor CodeUri: ../../packages/ Handler: nhsNotifyLambda.handler - Role: !GetAtt NHSNotifyLambdaResources.Outputs.LambdaRoleArn + Role: !GetAtt NotifyProcessorResources.Outputs.LambdaRoleArn Environment: Variables: LOG_LEVEL: !Ref LogLevel @@ -388,7 +388,7 @@ Resources: Properties: Name: !Sub ${StackName}-NHSNotifySchedule ScheduleExpression: "rate(1 minute)" - RoleArn: !GetAtt NHSNotifyLambdaScheduleEventRole.Arn + RoleArn: !GetAtt NotifyProcessorScheduleEventRole.Arn Metadata: BuildMethod: esbuild guard: @@ -405,14 +405,14 @@ Resources: EntryPoints: - nhsNotifyLambda/src/nhsNotifyLambda.ts - NHSNotifyLambdaResources: + NotifyProcessorResources: 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}-NotifyProcessor + LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-NotifyProcessor LogRetentionInDays: !Ref LogRetentionInDays CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn EnableSplunk: !Ref EnableSplunk @@ -487,10 +487,10 @@ Outputs: - !GetAtt CheckPrescriptionStatusUpdates.Arn - "" - NHSNotifyLambdaFunctionName: + NotifyProcessorFunctionName: Description: The function name of the NHS Notify lambda - Value: !Ref NHSNotifyLambda + Value: !Ref NotifyProcessor - NHSNotifyLambdaFunctionArn: + NotifyProcessorFunctionArn: Description: The function ARN of the NHS Notify lambda - Value: !GetAtt NHSNotifyLambda.Arn + Value: !GetAtt NotifyProcessor.Arn diff --git a/packages/updatePrescriptionStatus/src/utils/sqsClient.ts b/packages/updatePrescriptionStatus/src/utils/sqsClient.ts index 27460f5c92..a62bae396b 100644 --- a/packages/updatePrescriptionStatus/src/utils/sqsClient.ts +++ b/packages/updatePrescriptionStatus/src/utils/sqsClient.ts @@ -55,7 +55,7 @@ export async function pushPrescriptionToNotificationSQS( 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") @@ -73,7 +73,7 @@ export async function pushPrescriptionToNotificationSQS( for (const batch of batches) { const entries = batch - .filter((item) => updateStatuses.includes(item.Status)) + .filter((item) => updateStatuses.includes(item.Status.toLowerCase())) // Build SQS batch entries with FIFO parameters .map((item, idx) => ({ Id: idx.toString(), @@ -92,7 +92,7 @@ export async function pushPrescriptionToNotificationSQS( } logger.info( - "Notification required. Pushing prescriptions with deduplication IDs", + "Notification required. Pushing prescriptions to the notifications SQS with the following SQS message IDs", {deduplicationIds: entries.map(e => e.MessageDeduplicationId), requestId} ) diff --git a/packages/updatePrescriptionStatus/tests/testSqsClient.test.ts b/packages/updatePrescriptionStatus/tests/testSqsClient.test.ts index ae8b640bb6..a6145ed547 100644 --- a/packages/updatePrescriptionStatus/tests/testSqsClient.test.ts +++ b/packages/updatePrescriptionStatus/tests/testSqsClient.test.ts @@ -64,8 +64,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() }) @@ -110,7 +110,7 @@ describe("Unit tests for pushPrescriptionToNotificationSQS", () => { }) expect(infoSpy).toHaveBeenCalledWith( - "Notification required. Pushing prescriptions with deduplication IDs", + "Notification required. Pushing prescriptions to the notifications SQS with the following SQS message IDs", expect.objectContaining({requestId: "req-789", deduplicationIds: expect.any(Array)}) ) expect(infoSpy).toHaveBeenCalledWith(