From 74e5713750a07b5557c64b04303d990f58cd0a31 Mon Sep 17 00:00:00 2001 From: tstephen-nhs <231503406+tstephen-nhs@users.noreply.github.com> Date: Wed, 25 Mar 2026 14:36:05 +0000 Subject: [PATCH 1/2] fix: new index for post dated --- SAMtemplates/tables/main.yaml | 23 +++++++++++++++++-- packages/gsul/src/dynamoDBclient.ts | 3 ++- .../gsul/tests/testRunDynamoDBQueries.test.ts | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/SAMtemplates/tables/main.yaml b/SAMtemplates/tables/main.yaml index b0c232c21c..e0185c2df4 100644 --- a/SAMtemplates/tables/main.yaml +++ b/SAMtemplates/tables/main.yaml @@ -184,8 +184,6 @@ Resources: - TerminalStatus - LastModified - Status - # TODO: Remove this when we deprecate post dated prescriptions. - - PostDatedLastModifiedSetAt ProjectionType: INCLUDE ProvisionedThroughput: !If - EnableDynamoDBAutoScalingCondition @@ -222,6 +220,27 @@ Resources: - ReadCapacityUnits: 1 WriteCapacityUnits: !Ref MinWritePrescriptionStatusUpdatesCapacity - !Ref "AWS::NoValue" + - IndexName: PharmacyODSCodePrescriptionIDIndexIncPostDated + KeySchema: + - AttributeName: PharmacyODSCode + KeyType: HASH + - AttributeName: PrescriptionID + KeyType: RANGE + Projection: + NonKeyAttributes: + - PatientNHSNumber + - LineItemID + - TerminalStatus + - LastModified + - Status + # TODO: Remove this when we deprecate post dated prescriptions. + - PostDatedLastModifiedSetAt + ProjectionType: INCLUDE + ProvisionedThroughput: !If + - EnableDynamoDBAutoScalingCondition + - ReadCapacityUnits: 1 + WriteCapacityUnits: !Ref MinWritePrescriptionStatusUpdatesCapacity + - !Ref "AWS::NoValue" Tags: - Key: "EPS-Tablename" Value: "PrescriptionStatusUpdates" diff --git a/packages/gsul/src/dynamoDBclient.ts b/packages/gsul/src/dynamoDBclient.ts index 1aa871bd39..39ab3eb62d 100644 --- a/packages/gsul/src/dynamoDBclient.ts +++ b/packages/gsul/src/dynamoDBclient.ts @@ -50,7 +50,8 @@ export async function getItemsUpdatesForPrescription( export function createQueryCommandInput(odsCode: string, prescriptionID: string): QueryCommandInput { return { TableName: tableName, - IndexName: "PharmacyODSCodePrescriptionIDIndex", + // TODO: revert to PharmacyODSCodePrescriptionIDIndex once post-dated no longer required + IndexName: "PharmacyODSCodePrescriptionIDIndexIncPostDated", KeyConditionExpression: "PrescriptionID = :inputPrescriptionID AND PharmacyODSCode = :inputPharmacyODSCode", ExpressionAttributeValues: { ":inputPharmacyODSCode": odsCode.toUpperCase(), diff --git a/packages/gsul/tests/testRunDynamoDBQueries.test.ts b/packages/gsul/tests/testRunDynamoDBQueries.test.ts index 2371588b07..b60c00e1b2 100644 --- a/packages/gsul/tests/testRunDynamoDBQueries.test.ts +++ b/packages/gsul/tests/testRunDynamoDBQueries.test.ts @@ -48,7 +48,7 @@ describe("testing dynamoDBClient", () => { const expected = { TableName: undefined, - IndexName: "PharmacyODSCodePrescriptionIDIndex", + IndexName: "PharmacyODSCodePrescriptionIDIndexIncPostDated", KeyConditionExpression: "PrescriptionID = :inputPrescriptionID AND PharmacyODSCode = :inputPharmacyODSCode", ExpressionAttributeValues: { ":inputPharmacyODSCode": "ODSCODE", From 7a6d1e8956aaaa6d16b13a372a65f582fa3ee340 Mon Sep 17 00:00:00 2001 From: tstephen-nhs <231503406+tstephen-nhs@users.noreply.github.com> Date: Wed, 25 Mar 2026 15:16:02 +0000 Subject: [PATCH 2/2] chore: add scaling policy for new index --- SAMtemplates/tables/main.yaml | 54 +++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/SAMtemplates/tables/main.yaml b/SAMtemplates/tables/main.yaml index e0185c2df4..666479584f 100644 --- a/SAMtemplates/tables/main.yaml +++ b/SAMtemplates/tables/main.yaml @@ -233,14 +233,14 @@ Resources: - TerminalStatus - LastModified - Status - # TODO: Remove this when we deprecate post dated prescriptions. + # TODO: Remove this when we deprecate post dated prescriptions. - PostDatedLastModifiedSetAt ProjectionType: INCLUDE ProvisionedThroughput: !If - EnableDynamoDBAutoScalingCondition - ReadCapacityUnits: 1 WriteCapacityUnits: !Ref MinWritePrescriptionStatusUpdatesCapacity - - !Ref "AWS::NoValue" + - !Ref "AWS::NoValue" Tags: - Key: "EPS-Tablename" Value: "PrescriptionStatusUpdates" @@ -356,6 +356,56 @@ Resources: PredefinedMetricSpecification: PredefinedMetricType: DynamoDBReadCapacityUtilization + PharmacyIndexIncPostDatedScalingWriteTarget: + Type: AWS::ApplicationAutoScaling::ScalableTarget + Condition: EnableDynamoDBAutoScalingCondition + Properties: + MinCapacity: !Ref MinWritePrescriptionStatusUpdatesCapacity + MaxCapacity: !Ref MaxWritePrescriptionStatusUpdatesCapacity + ResourceId: !Sub table/${PrescriptionStatusUpdatesTable}/index/PharmacyODSCodePrescriptionIDIndexIncPostDated + RoleARN: !GetAtt DynamoDbScalingRole.Arn + ScalableDimension: "dynamodb:index:WriteCapacityUnits" + ServiceNamespace: dynamodb + + PharmacyIndexIncPostDatedScalingWritePolicy: + Type: AWS::ApplicationAutoScaling::ScalingPolicy + Condition: EnableDynamoDBAutoScalingCondition + Properties: + PolicyName: PharmacyIndexIncPostDatedWriteScalingPolicy + PolicyType: TargetTrackingScaling + ScalingTargetId: !Ref PharmacyIndexIncPostDatedScalingWriteTarget + TargetTrackingScalingPolicyConfiguration: + TargetValue: 50 + ScaleInCooldown: 600 + ScaleOutCooldown: 0 + PredefinedMetricSpecification: + PredefinedMetricType: DynamoDBWriteCapacityUtilization + + PharmacyIndexIncPostDatedScalingReadTarget: + Type: AWS::ApplicationAutoScaling::ScalableTarget + Condition: EnableDynamoDBAutoScalingCondition + Properties: + MaxCapacity: 100 + MinCapacity: 1 + ResourceId: !Sub table/${PrescriptionStatusUpdatesTable}/index/PharmacyODSCodePrescriptionIDIndexIncPostDated + RoleARN: !GetAtt DynamoDbScalingRole.Arn + ScalableDimension: "dynamodb:index:ReadCapacityUnits" + ServiceNamespace: dynamodb + + PharmacyIndexIncPostDatedScalingReadPolicy: + Type: AWS::ApplicationAutoScaling::ScalingPolicy + Condition: EnableDynamoDBAutoScalingCondition + Properties: + PolicyName: PharmacyIndexIncPostDatedReadScalingPolicy + PolicyType: TargetTrackingScaling + ScalingTargetId: !Ref PharmacyIndexIncPostDatedScalingReadTarget + TargetTrackingScalingPolicyConfiguration: + TargetValue: 70 + ScaleInCooldown: 600 + ScaleOutCooldown: 10 + PredefinedMetricSpecification: + PredefinedMetricType: DynamoDBReadCapacityUtilization + NHSNumberIndexScalingWriteTarget: Type: AWS::ApplicationAutoScaling::ScalableTarget Condition: EnableDynamoDBAutoScalingCondition