I can’t get the method-level API throttling on AWS Gateway for a REST API to work without manually adjusting it on the AWS UI Console.
I typically set it via an “override” in the stage settings.
Is there a way this can be done in AWS CDK?
I have noticed there are two options for method-level throttling in the apigateway.RestApi
.
-
You can add
methodOptions
when creating the gateway, but this doesn’t actually work, as the changes never sync up to the AWS UI console (as an ‘override’ for the method within the Stage). -
You can also alter the Usage Plan under
throttling
to specify fine-grained methods, but you must also activate the coarse-grained (whole of API) throttling too.
See https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.UsagePlanPerApiStage.html
const usagePlan = new apigateway.UsagePlan(context, `UsagePlan`, {
name: `UsagePlan`,
description: `Usage Plan for API`,
throttle: {
rateLimit: 10000,
burstLimit: 10000
},
apiStages: [
{
api: gateway,
stage: gateway.deploymentStage,
throttle: [
{
method: postMethod,
throttle: {
rateLimit: 20,
burstLimit: 100
}
}
]
}
]
})