AWS - API 密钥可用于无服务器离线框架?

AWS - API keys available on the Serverless Offline framework?

我使用Serverless Offline开发一个Web项目

我需要 API 密钥 来访问 Serverless AWS Lamda[=32 上的资源=].

我的服务提供商有一个serverless.yml。

Postman中,我访问了我的路线(http://127.0.0.1:3333/segments/UUID/test),我没有任何错误(as Forbidden message), Lambda 被执行...

test:
  handler: src/Api/segment.test
  events:
    - http:
        path: segments/{segmentUuid}/test
        method: post
        request:
          parameters:
            paths:
              segmentUuid: true
        private: true

有问题的路由不受私有保护。

https://www.npmjs.com/package/serverless-offline#token-authorizers

Serverless-offline will emulate the behaviour of APIG and create a random token that's printed on the screen. With this token you can access your private methods adding x-api-key: generatedToken to your request header. All api keys will share the same token. To specify a custom token use the --apiKey cli option.

命令将如下所示:

sls offline --apiKey any-pregenerated-key

对于本地开发人员,请在 serverless.yml:

中使用
custom:
  serverless-offline:
    apiKey: 'your-key-here'

或者里面的这个serverless.ts:

 custom: {
    'serverless-offline': {
      apiKey: 'your-key-here',
    },
  },