このフレームワーク楽しいな(API GatewayとLambdaの連携を一通り遊んだことがある人ならいじるのが楽しいと思う)
./serverless.ts
に下記設定を追加します。
apiGateway: { // 省略 apiKeys: [ { name: 'free-key', } ], usagePlan: { quota: { limit: 1000, period: 'MONTH' }, throttle: { burstLimit: 200, rateLimit: 100 } } }, // 省略
あとは個別のAPI設定に利用できるように設定します。
~/src/functions/hello/index.ts
import schema from './schema'; import { handlerPath } from '@libs/handler-resolver'; export default { handler: `${handlerPath(__dirname)}/handler.main`, events: [ { http: { method: 'post', path: 'hello', request: { schemas: { 'application/json': schema, }, }, private: true }, }, ], };
これでおk。あとはデプロイ成功するとkeyの確認ができます。
$ sls info --region us-west-2 Running "serverless" from node_modules # ... api keys: free-key: hogehogefugafuga # ...