Hello there :wave: I would like to thank you the w...
# help
t
Hello there 👋 I would like to thank you the wonderful team behind SST. I'm very happy to be a seed customer when I see the amazing product you build. I plan to migrate some services from
serverless-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? Thanks
f
Hey @Thibault 👋 Welcome!
Are you thinking about importing the existing API into SST, or creating a new one?
t
creating a new one
f
You can do something like this:
Copy code
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);
t
Ok I see 👍
Thank for the quick reply! The support is at the same level of your product ❤️
f
Yup yup, I was just going to suggest to use
sst.ApiGatewayV1Api
to create a REST API first. Get that to work. And then you can do whatever u want with
api.restApi
t
Thank you have a good evening 👋
f
One thing to add is that if u look at the example in the link above, they are setting the
{ apiKeyRequired: true }
for each route, you can define that in
sst.ApiGatewayV1Api
like this:
Copy code
new ApiGatewayV1Api(this, "Api", {
  routes: {
    "GET /public": "src/public.main",
    "GET /private": {
      function: "src/private.main",
      methodOptions: {
        apiKeyRequired: true,
      },
    },
  },
});