https://serverless-stack.com/ logo
#sst
Title
# sst
d

Dennis Dang

03/23/2021, 12:57 AM
I'd like to attach a usage plan to throttle per stage/routes/etc. CDK allows me to create plans like so
const usagePlan = new apigateway.UsagePlan(scope, id, { name:  "PoorDevPlan",throttle: { rateLimit: 5000 } });
. But how can I attach this to the current Api construct?
Hmm, a workaround is possible if I can grab the underlying cdk construct.
f

Frank

03/23/2021, 1:04 AM
@Dennis Dang just to add a bit of context, AWS offers two types of API projects, Rest API and Http API (if you try to create a new API Gateway project in AWS, you are asked to pick one)
d

Dennis Dang

03/23/2021, 1:05 AM
I believe the one that comes by default with sls framework and SST is the Http API, correct?
f

Frank

03/23/2021, 1:05 AM
Http API is the newer offering that’s faster, cheaper, has a better design, but with lesser features.
sst.Api
uses Http API behind the scnene.
yeah
Http Api doesn’t support usage plan at the moment
d

Dennis Dang

03/23/2021, 1:05 AM
Okay so from this, are you hinting that usage plans are only for the Rest API?
f

Frank

03/23/2021, 1:06 AM
yeah
d

Dennis Dang

03/23/2021, 1:06 AM
Wow, no wonder. Thanks Frank
f

Frank

03/23/2021, 1:07 AM
what’s your timeline on this? b/c we are looking to create a construct (ie.
sst.LegacyApi
) that uses the Rest API. Like the discussion you reference.
d

Dennis Dang

03/23/2021, 1:09 AM
Looking out a couple weeks. I don't think we'd want to switch to the Rest API unless there were other significant wins. This won't block us, since we can at least rely on API Gateway's high but default throttle limits.
f

Frank

03/23/2021, 1:15 AM
I found this.. apparently you can configure route-level throttling for Http Api https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-throttling.html
d

Dennis Dang

03/23/2021, 1:16 AM
I'm looking at that too right now. But the aws-apigateway and v2's api doesn't make it readily accessible. Easy to configure via the console
f

Frank

03/23/2021, 1:18 AM
yeah.. it’s not supported by the apigatewayv2 construct yet.. but you can set it at the CloudFormation level https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigatewayv2.CfnStage.RouteSettingsProperty.html
if u guys end up blocked by this.. lemme know, I can look into if
sst.Api
can expose something u guys can use to set this
d

Dennis Dang

03/23/2021, 1:25 AM
That would keep the code really neat if we can configure per route. I'll try the cloudformation path first and share.
d

Dmitry Pavluk

03/23/2021, 8:19 PM
We're deploying a public-facing sandbox this week so a programmatic way to configure API usage/throttling would go a long way towards helping us sleep at night haha