我们正在使用AWS API Gateway,它为HTTP endpoints 提供POST方法,我们可以在此图像上调用:
enter image description here

此网关使用Lambda代理集成调用我们的AWS Lambda函数 . 问题是当我们从外部REST客户端调用Gateway时,我们传递给函数处理程序的输入对象没有填充字段 . 如果尝试使用相同的标头和正文在测试模式(来自AWS Gateway控制台页面)中调用Gateway,我们会看到Lambda处理程序获得正确填充的请求对象 . 以下日志中有一些细节 .

在测试模式调用中记录方法请求 before transformation 的记录:

Execution log for request test-request
Wed Aug 30 16:05:02 UTC 2017 : Starting execution for request: test-invoke-request
Wed Aug 30 16:05:02 UTC 2017 : HTTP Method: POST, Resource Path: /member/alert/tmv/style
Wed Aug 30 16:05:02 UTC 2017 : Method request path: {}
Wed Aug 30 16:05:02 UTC 2017 : Method request query string: {}
Wed Aug 30 16:05:02 UTC 2017 : Method request headers: {authorization=************************************g8_A5Q}
Wed Aug 30 16:05:02 UTC 2017 : Method request body before transformations: { "styleId": "401630051" }

在测试模式调用 after transformation 中记录与方法请求主体相关的记录:

Wed Aug 30 16:05:02 UTC 2017 : Endpoint request body after transformations: {"resource":"/member/alert/tmv/style","path":"/member/alert/tmv/style","httpMethod":"POST","headers":{"authorization":"************************************g8_A5Q [TRUNCATED]

正如您在转换后看到的,请求正文包含填充的字段,如资源,路径, Headers 等 . 这是正确的行为 . 但是,当我不是从AWS控制台调用API网关时,而是从我的HTTP客户端调用API时,我在日志中看到请求字段为空 . 任何想法为什么会这样?