Skip to content

Commit c6c7c1f

Browse files
authored
Chore: [AEA-6055] - new index for post dated (#2910)
## Summary - 🤖 Operational or Infrastructure Change ### Details [Fix: AEA-6055 - debugging issues with post-dated updates](#2814) passed on a PR branch becasue we create a new table there but [failed](https://github.com/NHSDigital/eps-prescription-status-update-api/actions/runs/23487029492) on merge to main: > This AWS::dynamodb::Table resource is in a UPDATE_FAILED state. Resource handler returned message: "Cannot update GSI's properties other than Provisioned Throughput and Contributor Insights Specification. You can create a new GSI with a different name." (RequestToken: dfb5cd2a-c90c-1412-45a9-b4ae52322456, HandlerErrorCode: InvalidRequest) So this PR creates a new secondary index to be used temporarily until we can disable post-dated updates functionality. This is why the original index is left in place.
1 parent b0a05ab commit c6c7c1f

3 files changed

Lines changed: 74 additions & 4 deletions

File tree

SAMtemplates/tables/main.yaml

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ Resources:
184184
- TerminalStatus
185185
- LastModified
186186
- Status
187-
# TODO: Remove this when we deprecate post dated prescriptions.
188-
- PostDatedLastModifiedSetAt
189187
ProjectionType: INCLUDE
190188
ProvisionedThroughput: !If
191189
- EnableDynamoDBAutoScalingCondition
@@ -222,6 +220,27 @@ Resources:
222220
- ReadCapacityUnits: 1
223221
WriteCapacityUnits: !Ref MinWritePrescriptionStatusUpdatesCapacity
224222
- !Ref "AWS::NoValue"
223+
- IndexName: PharmacyODSCodePrescriptionIDIndexIncPostDated
224+
KeySchema:
225+
- AttributeName: PharmacyODSCode
226+
KeyType: HASH
227+
- AttributeName: PrescriptionID
228+
KeyType: RANGE
229+
Projection:
230+
NonKeyAttributes:
231+
- PatientNHSNumber
232+
- LineItemID
233+
- TerminalStatus
234+
- LastModified
235+
- Status
236+
# TODO: Remove this when we deprecate post dated prescriptions.
237+
- PostDatedLastModifiedSetAt
238+
ProjectionType: INCLUDE
239+
ProvisionedThroughput: !If
240+
- EnableDynamoDBAutoScalingCondition
241+
- ReadCapacityUnits: 1
242+
WriteCapacityUnits: !Ref MinWritePrescriptionStatusUpdatesCapacity
243+
- !Ref "AWS::NoValue"
225244
Tags:
226245
- Key: "EPS-Tablename"
227246
Value: "PrescriptionStatusUpdates"
@@ -337,6 +356,56 @@ Resources:
337356
PredefinedMetricSpecification:
338357
PredefinedMetricType: DynamoDBReadCapacityUtilization
339358

359+
PharmacyIndexIncPostDatedScalingWriteTarget:
360+
Type: AWS::ApplicationAutoScaling::ScalableTarget
361+
Condition: EnableDynamoDBAutoScalingCondition
362+
Properties:
363+
MinCapacity: !Ref MinWritePrescriptionStatusUpdatesCapacity
364+
MaxCapacity: !Ref MaxWritePrescriptionStatusUpdatesCapacity
365+
ResourceId: !Sub table/${PrescriptionStatusUpdatesTable}/index/PharmacyODSCodePrescriptionIDIndexIncPostDated
366+
RoleARN: !GetAtt DynamoDbScalingRole.Arn
367+
ScalableDimension: "dynamodb:index:WriteCapacityUnits"
368+
ServiceNamespace: dynamodb
369+
370+
PharmacyIndexIncPostDatedScalingWritePolicy:
371+
Type: AWS::ApplicationAutoScaling::ScalingPolicy
372+
Condition: EnableDynamoDBAutoScalingCondition
373+
Properties:
374+
PolicyName: PharmacyIndexIncPostDatedWriteScalingPolicy
375+
PolicyType: TargetTrackingScaling
376+
ScalingTargetId: !Ref PharmacyIndexIncPostDatedScalingWriteTarget
377+
TargetTrackingScalingPolicyConfiguration:
378+
TargetValue: 50
379+
ScaleInCooldown: 600
380+
ScaleOutCooldown: 0
381+
PredefinedMetricSpecification:
382+
PredefinedMetricType: DynamoDBWriteCapacityUtilization
383+
384+
PharmacyIndexIncPostDatedScalingReadTarget:
385+
Type: AWS::ApplicationAutoScaling::ScalableTarget
386+
Condition: EnableDynamoDBAutoScalingCondition
387+
Properties:
388+
MaxCapacity: 100
389+
MinCapacity: 1
390+
ResourceId: !Sub table/${PrescriptionStatusUpdatesTable}/index/PharmacyODSCodePrescriptionIDIndexIncPostDated
391+
RoleARN: !GetAtt DynamoDbScalingRole.Arn
392+
ScalableDimension: "dynamodb:index:ReadCapacityUnits"
393+
ServiceNamespace: dynamodb
394+
395+
PharmacyIndexIncPostDatedScalingReadPolicy:
396+
Type: AWS::ApplicationAutoScaling::ScalingPolicy
397+
Condition: EnableDynamoDBAutoScalingCondition
398+
Properties:
399+
PolicyName: PharmacyIndexIncPostDatedReadScalingPolicy
400+
PolicyType: TargetTrackingScaling
401+
ScalingTargetId: !Ref PharmacyIndexIncPostDatedScalingReadTarget
402+
TargetTrackingScalingPolicyConfiguration:
403+
TargetValue: 70
404+
ScaleInCooldown: 600
405+
ScaleOutCooldown: 10
406+
PredefinedMetricSpecification:
407+
PredefinedMetricType: DynamoDBReadCapacityUtilization
408+
340409
NHSNumberIndexScalingWriteTarget:
341410
Type: AWS::ApplicationAutoScaling::ScalableTarget
342411
Condition: EnableDynamoDBAutoScalingCondition

packages/gsul/src/dynamoDBclient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export async function getItemsUpdatesForPrescription(
5050
export function createQueryCommandInput(odsCode: string, prescriptionID: string): QueryCommandInput {
5151
return {
5252
TableName: tableName,
53-
IndexName: "PharmacyODSCodePrescriptionIDIndex",
53+
// TODO: revert to PharmacyODSCodePrescriptionIDIndex once post-dated no longer required
54+
IndexName: "PharmacyODSCodePrescriptionIDIndexIncPostDated",
5455
KeyConditionExpression: "PrescriptionID = :inputPrescriptionID AND PharmacyODSCode = :inputPharmacyODSCode",
5556
ExpressionAttributeValues: {
5657
":inputPharmacyODSCode": odsCode.toUpperCase(),

packages/gsul/tests/testRunDynamoDBQueries.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe("testing dynamoDBClient", () => {
4848

4949
const expected = {
5050
TableName: undefined,
51-
IndexName: "PharmacyODSCodePrescriptionIDIndex",
51+
IndexName: "PharmacyODSCodePrescriptionIDIndexIncPostDated",
5252
KeyConditionExpression: "PrescriptionID = :inputPrescriptionID AND PharmacyODSCode = :inputPharmacyODSCode",
5353
ExpressionAttributeValues: {
5454
":inputPharmacyODSCode": "ODSCODE",

0 commit comments

Comments
 (0)