是否有发送到 Lambda 的 AWS 网关事件的官方文档?

Is there any official documentation of AWS Gateway events sent to Lambda?

我一直在搜索从集成(例如 AWS API 网关)发送到 AWS Lambda 的数据类型的某种官方文档。我已经能够在 API 网关文档中找到一些 "Examples",例如 here and here。创建一个仅将输入事件作为输出回显并检查输出的 Lambda 也相对容易。例如(使用 REST 类型 API 与 LAMBDA_PROXY 集成)你会得到类似的东西:

{
    "resource": "/another/{parameter}",
    "path": "/another/some-parameter",
    "httpMethod": "GET",
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate, br",
        ...
    },
    "multiValueHeaders": {
        "Accept": [
            "*/*"
        ],
        "Accept-Encoding": [
            "gzip, deflate, br"
        ],
        ...
    },
    "queryStringParameters": null,
    "multiValueQueryStringParameters": null,
    "pathParameters": {
        "parameter": "some-parameter"
    },
    "stageVariables": null,
    "requestContext": {
        "resourceId": "some-id",
        "resourcePath": "/another/{parameter}",
        "httpMethod": "GET",
        ...
    },
    "body": null,
    "isBase64Encoded": false
}

但这并没有告诉我什么字段我总是可以,或者只是有时,期望在有效载荷或字段类型中。

我最需要输入一些字段的是 Definitely Typed 项目中的 aws-lambda TypeScript typings

对于 API 网关和其他 AWS 服务集成的 Lambda 事件负载的结构和类型,是否有任何更详细或更一般的官方来源可供我参考?

这是迄今为止我最接近的答案。如果有人有更详细的(或一般信息),我很乐意接受。在 Lambda documentation 你可以看到(我强调的):

The runtime passes three arguments to the handler method. The first argument is the event object, which contains information from the invoker. The invoker passes this information as a JSON-formatted string when it calls Invoke, and the runtime converts it to an object. When an AWS service invokes your function, the event structure varies by service.

在“Working with other services" in the lambda documentation we only find the examples presented in the question. Instead we can look in the documentation for the service in question, e.g. API Gateway. For API Gateway, under "Working with [HTTP/REST] APIs", you will find descriptions of the event fields for REST and HTTP 下输入 APIs.

话虽如此,所提供的文档仍仅将描述的有效载荷结构称为 "examples"。它只为您提供字段名称和一些基本结构。必须从示例中推断出数据类型,请参阅下面的代码片段。

对于您可能希望与 Lambda 集成的其他服务,情况似乎类似:

所有可找到的都是有效负载的示例,一些在服务自己的开发人员指南中,其他在 Lambda 的开发人员指南中。

HTTP v2.0

以下是使用 HTTP 类型 API 的版本 2.0 的负载格式示例。对于版本 1,请参阅 HTTP type integration docs.

{
      version: '2.0',
      routeKey: '$default',
      rawPath: '/my/path',
      rawQueryString: 'parameter1=value1&parameter1=value2&parameter2=value',
      cookies: [ 'cookie1', 'cookie2' ],
      headers: {
        'Header1': 'value1',
        'Header2': 'value2'
      },
      queryStringParameters: { parameter1: 'value1,value2', parameter2: 'value' },
      requestContext: {
        accountId: '123456789012',
        apiId: 'api-id',
        authorizer: { jwt: {
            claims: {'claim1': 'value1', 'claim2': 'value2'},
            scopes: ['scope1', 'scope2']
            }
        },
        domainName: 'id.execute-api.us-east-1.amazonaws.com',
        domainPrefix: 'id',
        http: {
          method: 'POST',
          path: '/my/path',
          protocol: 'HTTP/1.1',
          sourceIp: 'IP',
          userAgent: 'agent'
        },
        requestId: 'id',
        routeKey: '$default',
        stage: '$default',
        time: '12/Mar/2020:19:03:58 +0000',
        timeEpoch: 1583348638390
      },
      body: 'Hello from Lambda',
      pathParameters: {'parameter1': 'value1'},
      isBase64Encoded: false,
      stageVariables: {'stageVariable1': 'value1', 'stageVariable2': 'value2'}
    }

REST v3.0

以下是使用 REST 类型 API 的版本 3.0 的负载格式示例。对于 2.0 版,请参阅 REST type integration docs.

{
   "openapi": "3.0.0",
   "info": {
      "version": "2016-09-12T17:50:37Z",
      "title": "ProxyIntegrationWithLambda"
   },
   "paths": {
      "/{proxy+}": {
         "x-amazon-apigateway-any-method": {
            "parameters": [
               {
                  "name": "proxy",
                  "in": "path",
                  "required": true,
                  "schema": {
                     "type": "string"
                  }
               }
            ],
            "responses": {},
            "x-amazon-apigateway-integration": {
               "responses": {
                  "default": {
                     "statusCode": "200"
                  }
               },
               "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:SimpleLambda4ProxyResource/invocations",
               "passthroughBehavior": "when_no_match",
               "httpMethod": "POST",
               "cacheNamespace": "roq9wj",
               "cacheKeyParameters": [
                  "method.request.path.proxy"
               ],
               "type": "aws_proxy"
            }
         }
      }
   },
   "servers": [
      {
         "url": "https://gy415nuibc.execute-api.us-east-1.amazonaws.com/{basePath}",
         "variables": {
            "basePath": {
              "default": "/testStage"
            }
         }
      }
   ]
}