Skip to content

Commit

Permalink
Fix: [AEA-4338] - scale dynamodb and set limits on apigee (#454)
Browse files Browse the repository at this point in the history
## Summary

- Routine Change

### Details

- set initial write capacity of dynamodb to 50 with a scale up to 600
- set spike arrest policies on apis of  20000 requests per minute
  • Loading branch information
anthony-nhs authored Aug 12, 2024
1 parent 7aa37ba commit 6c36659
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 28 deletions.
68 changes: 51 additions & 17 deletions SAMtemplates/tables/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ Parameters:
EnableDynamoDBAutoScaling:
Type: String

MinWritePrescriptionStatusUpdatesCapacity:
Type: Number
Default: 50

MaxWritePrescriptionStatusUpdatesCapacity:
Type: Number
Default: 600

Conditions:
EnableDynamoDBAutoScalingCondition: !Equals
- true
Expand Down Expand Up @@ -81,7 +89,7 @@ Resources:
ProvisionedThroughput: !If
- EnableDynamoDBAutoScalingCondition
- ReadCapacityUnits: 1
WriteCapacityUnits: 1
WriteCapacityUnits: !Ref MinWritePrescriptionStatusUpdatesCapacity
- !Ref "AWS::NoValue"
SSESpecification:
KMSMasterKeyId: !Ref PrescriptionStatusUpdatesKMSKey
Expand All @@ -105,7 +113,7 @@ Resources:
ProvisionedThroughput: !If
- EnableDynamoDBAutoScalingCondition
- ReadCapacityUnits: 1
WriteCapacityUnits: 1
WriteCapacityUnits: !Ref MinWritePrescriptionStatusUpdatesCapacity
- !Ref "AWS::NoValue"
- IndexName: PatientNHSNumberIndex
KeySchema:
Expand All @@ -116,7 +124,7 @@ Resources:
ProvisionedThroughput: !If
- EnableDynamoDBAutoScalingCondition
- ReadCapacityUnits: 1
WriteCapacityUnits: 1
WriteCapacityUnits: !Ref MinWritePrescriptionStatusUpdatesCapacity
- !Ref "AWS::NoValue"

PrescriptionStatusUpdatesResources:
Expand Down Expand Up @@ -171,8 +179,8 @@ Resources:
DependsOn: PrescriptionStatusUpdatesTable
Condition: EnableDynamoDBAutoScalingCondition
Properties:
MaxCapacity: 100
MinCapacity: 1
MinCapacity: !Ref MinWritePrescriptionStatusUpdatesCapacity
MaxCapacity: !Ref MaxWritePrescriptionStatusUpdatesCapacity
ResourceId: !Sub table/${PrescriptionStatusUpdatesTable}
RoleARN: !GetAtt DynamoDbScalingRole.Arn
ScalableDimension: "dynamodb:table:WriteCapacityUnits"
Expand All @@ -186,9 +194,9 @@ Resources:
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref PrescriptionStatusUpdatesTableWriteScalingTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 70
ScaleInCooldown: 60
ScaleOutCooldown: 60
TargetValue: 50
ScaleInCooldown: 600
ScaleOutCooldown: 0
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBWriteCapacityUtilization

Expand Down Expand Up @@ -223,8 +231,8 @@ Resources:
DependsOn: PrescriptionStatusUpdatesTable
Condition: EnableDynamoDBAutoScalingCondition
Properties:
MaxCapacity: 100
MinCapacity: 1
MinCapacity: !Ref MinWritePrescriptionStatusUpdatesCapacity
MaxCapacity: !Ref MaxWritePrescriptionStatusUpdatesCapacity
ResourceId: !Sub table/${PrescriptionStatusUpdatesTable}/index/PharmacyODSCodePrescriptionIDIndex
RoleARN: !GetAtt DynamoDbScalingRole.Arn
ScalableDimension: "dynamodb:index:WriteCapacityUnits"
Expand All @@ -238,19 +246,45 @@ Resources:
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref PharmacyIndexScalingWriteTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 70
ScaleInCooldown: 60
ScaleOutCooldown: 60
TargetValue: 50
ScaleInCooldown: 600
ScaleOutCooldown: 0
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBWriteCapacityUtilization

NHSNumberIndexScalingWriteTarget:
PharmacyIndexScalingReadTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
DependsOn: PrescriptionStatusUpdatesTable
Condition: EnableDynamoDBAutoScalingCondition
Properties:
MaxCapacity: 100
MinCapacity: 1
ResourceId: !Sub table/${PrescriptionStatusUpdatesTable}/index/PharmacyODSCodePrescriptionIDIndex
RoleARN: !GetAtt DynamoDbScalingRole.Arn
ScalableDimension: "dynamodb:index:ReadCapacityUnits"
ServiceNamespace: dynamodb

PharmacyIndexScalingReadPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Condition: EnableDynamoDBAutoScalingCondition
Properties:
PolicyName: NHSNumberIndexReadScalingPolicy
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref PharmacyIndexScalingReadTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 70
ScaleInCooldown: 600
ScaleOutCooldown: 10
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBReadCapacityUtilization

NHSNumberIndexScalingWriteTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
DependsOn: PrescriptionStatusUpdatesTable
Condition: EnableDynamoDBAutoScalingCondition
Properties:
MinCapacity: !Ref MinWritePrescriptionStatusUpdatesCapacity
MaxCapacity: !Ref MaxWritePrescriptionStatusUpdatesCapacity
ResourceId: !Sub table/${PrescriptionStatusUpdatesTable}/index/PatientNHSNumberIndex
RoleARN: !GetAtt DynamoDbScalingRole.Arn
ScalableDimension: "dynamodb:index:WriteCapacityUnits"
Expand All @@ -264,9 +298,9 @@ Resources:
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref NHSNumberIndexScalingWriteTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 70
ScaleInCooldown: 60
ScaleOutCooldown: 60
TargetValue: 50
ScaleInCooldown: 600
ScaleOutCooldown: 0
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBWriteCapacityUtilization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,8 @@ x-nhsd-apim:
header: attribute-name
ratelimiting:
proxy:
timeunit: "second"
limit: 40
limit: 20000
timeunit: minute
app-default:
limit: 20000
timeunit: minute
25 changes: 16 additions & 9 deletions packages/specification/eps-prescription-status-update-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ info:
description: |
## Overview
Use this API to enable dispensing suppliers to push status information about electronic prescriptions to patients on a national scale via the NHS App (and potential other third parties in the future).
The overall aim of the service is to reduce burden to frontline NHS services by reducing the number of routine patient queries about their prescriptions.
You can:
* enable patients to know when their prescription is ready
* enable dispensing suppliers to push status information about electronic prescriptions
Expand Down Expand Up @@ -58,7 +58,7 @@ info:
* 200 to 299 if it succeeded, including code 202 if it was accepted by an API that needs to wait for further action
* 400 to 499 if it failed because of a client error by your application
* 500 to 599 if it failed because of an error on our server
Errors specific to each API are shown in the Endpoints section, under Response. See our [reference guide](https://digital.nhs.uk/developer/guides-and-documentation/reference-guide#http-status-codes) for more on errors.
## Open source
You might find the following [open source](https://digital.nhs.uk/developer/guides-and-documentation/reference-guide#open-source) resources useful:
Expand Down Expand Up @@ -128,7 +128,8 @@ paths:
$ref: examples/request-ready-to-dispatch.json
ready-to-dispatch-partial:
summary: ready-to-dispatch-partial
description: A request message contains tracking status `Ready to Dispatch -
description:
A request message contains tracking status `Ready to Dispatch -
Partial`.
value:
$ref: examples/request-ready-to-dispatch-partial.json
Expand Down Expand Up @@ -166,12 +167,14 @@ paths:
$ref: "#/components/schemas/ResponseBundle"
examples:
single-item:
description: A successful response to a UpdatePrescriptionStatus request,
description:
A successful response to a UpdatePrescriptionStatus request,
contains a single item.
value:
$ref: examples/response-single-item.json
multiple-items:
description: A successful response to a UpdatePrescriptionStatus request,
description:
A successful response to a UpdatePrescriptionStatus request,
contains multiple items.
value:
$ref: examples/response-multiple-items.json
Expand Down Expand Up @@ -342,7 +345,8 @@ components:
- Bundle
type:
type: string
description: Denotes that the bundle is a list of status updates to be performed
description:
Denotes that the bundle is a list of status updates to be performed
as one transaction.
enum:
- transaction
Expand Down Expand Up @@ -409,5 +413,8 @@ x-nhsd-apim:
header: show-all-suppliers
ratelimiting:
proxy:
timeunit: second
limit: 60
limit: 20000
timeunit: minute
app-default:
limit: 20000
timeunit: minute

0 comments on commit 6c36659

Please sign in to comment.