使用serverless框架时如何使用默认请求模板?

How to use default request templates when using the serverless framework?

我知道我需要为 API 网关指定一个请求模板才能访问请求 headers。 The Serverless docs 说:

"Serverless ships with the following default request templates you can use out of the box:"

默认模板看起来可以访问我想要的内容(即请求 headers),但是您如何告诉 Serverless 使用它们?

"default request templates you can use out of the box" 指的是 lambda 集成,而不是 "default" 集成,您将参数留空。如果未定义集成,则它是默认集成。因此,在 http 下,添加 "integration: lambda".

然而,话虽如此,当您未指定集成时,您仍然应该可以访问 headers。

Lambda 集成
https://serverless.com/framework/docs/providers/aws/events/apigateway/#example-lambda-event-before-customization

functions:
  create:
    handler: posts.create
    events:
      - http:
          path: posts/create
          method: post
          integration: lambda

默认集成
https://serverless.com/framework/docs/providers/aws/events/apigateway/#example-lambda-proxy-event-default

functions:
  index:
    handler: handler.hello
    events:
      - http: GET hello