Lambda事件返回空对象 [英] Lambda event returns empty object

查看:108
本文介绍了Lambda事件返回空对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要访问 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆