Thibault
04/14/2021, 10:15 PMserverless-framework
to SST
but I have some ApiGateways protected by an api key. According to @Frank https://serverless-stack.slack.com/archives/C01JVDJQU2C/p1617958912086200 ApiGatewayV1Api
allows using Api Key
. I didn't find any example showing how to achieve this. Can someone provide me with an example? ThanksFrank
Frank
Thibault
04/14/2021, 10:19 PMFrank
const api = sst.ApiGatewayV1Api(this, "NewApi", ...);
const plan = api.restApi.addUsagePlan('UsagePlan', {
name: 'Easy',
throttle: {
rateLimit: 10,
burstLimit: 2
}
});
const key = api.restApi.addApiKey('ApiKey');
plan.addApiKey(key);
Thibault
04/14/2021, 10:23 PMThibault
04/14/2021, 10:23 PMThibault
04/14/2021, 10:24 PMFrank
sst.ApiGatewayV1Api
to create a REST API first. Get that to work. And then you can do whatever u want with api.restApi
Frank
Thibault
04/14/2021, 10:28 PMFrank
{ apiKeyRequired: true }
for each route, you can define that in sst.ApiGatewayV1Api
like this:
new ApiGatewayV1Api(this, "Api", {
routes: {
"GET /public": "src/public.main",
"GET /private": {
function: "src/private.main",
methodOptions: {
apiKeyRequired: true,
},
},
},
});