Lambda事件返回空对象 [英] Lambda event returns empty object
问题描述
我需要访问 event ["pathParameters"]
,但是该事件返回一个空对象.我使用 AWS Cloud9 IDE创建了该函数.
I need to access event["pathParameters"]
but the event returns an empty object. I created the function with AWS Cloud9 IDE.
这是我的简单功能:
def handler(event, context):
return {
'statusCode': 200,
'body': json.dumps(event),
'headers': {
'Content-Type': 'application/json'
}
}
推荐答案
事件
由调用lambda的有效负载设置.
event
is set by the payload you're invoking the lambda with.
使用API网关时,有效负载包括键 pathParameters
,但是当您使用lambda控制台进行测试时,您需要自己形成JSON.该控制台的模板部分确实包含API网关代理事件的示例.
When you use API gateway, that payload includes the key pathParameters
, but when you're testing using the lambda console you'll need to form the JSON yourself. The console does include an example of an API gateway proxy event in its templates section.
For a more complete reference see: https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-api-gateway-request
这篇关于Lambda事件返回空对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!