import json
def lambda_handler(event, context):
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": json.dumps(event['param'])
}
我不确定我做错了什么。我成功地设置了API网关,一个Python Lambda函数,通过Route53正确的DNS和一个有效的TLS证书…
我可以通过调用mydomain.com/Lambda访问我的Lambda,但我没有任何参数可以通过,只有这个错误。我已经尝试了5个令人沮丧的小时了。
通过mydomain.com/lambda调用时
errorMessage "'param'"
errorType "KeyError"
stackTrace
0 " File "/var/task/lambda_function.py", line 7, in lambda_handlern "body": json.dumps(event['param'])n"
通过API网关的"测试"调用时(此处一切正常(
Execution log for request
Tue Nov 05 22:42:47 UTC 2019 : Starting execution for request:
Tue Nov 05 22:42:47 UTC 2019 : HTTP Method: GET, Resource Path: /
Tue Nov 05 22:42:47 UTC 2019 : Method request path: {}
Tue Nov 05 22:42:47 UTC 2019 : Method request query string: {}
Tue Nov 05 22:42:47 UTC 2019 : Method request headers: {}
Tue Nov 05 22:42:47 UTC 2019 : Method request body before transformations:
Tue Nov 05 22:42:47 UTC 2019 : Endpoint request URI:
Tue Nov 05 22:42:47 UTC 2019 : Endpoint request headers: {x-amzn-lambda-integration-tag=Authorization=...[TRUNCATED]
Tue Nov 05 22:42:47 UTC 2019 : Endpoint request body after transformations:
{
"param" : "foo"
}
Tue Nov 05 22:42:47 UTC 2019 : Sending request to
Tue Nov 05 22:42:47 UTC 2019 : Received response. Status: 200, Integration latency: 36 ms
Tue Nov 05 22:42:47 UTC 2019 : Endpoint response headers: [...]
Tue Nov 05 22:42:47 UTC 2019 : Successfully completed execution
Tue Nov 05 22:42:47 UTC 2019 : Method completed with status: 200
最终成功(通过API网关的"测试"(
{
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": ""foo""
}
如何通过URL使其工作?我试着从客户端(浏览器(获取一些头参数,但要循序渐进地学习。当通过URL调用时,我似乎甚至无法从API网关传递任何东西到Lambda,但为什么?我在概念上没有得到什么?:(
我正确地设置了所有内容,但不知道我必须重新部署API才能公开进行更改。
答案是:再次部署API。