AWS Lambda nodejs函数中的事件对象为空 [英] Event Object is empty in AWS Lambda nodejs function

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

问题描述

我正在使用Lambda函数查询RDS MySQL数据库.为了获取一行,我将主键作为参数传递给URL(使用AWS API Gateway).示例网址为:

I am using Lambda function to query a RDS MySQL database. To fetch a row, I am passing the primary key as parameter in the URL (with AWS API Gateway). Example URL is:

https://aaaaaaa.execute-api.aaaaaaaaa .amazonaws.com/default/getresult?pk = 1245

在Lambda函数中,

In the Lambda function,

exports.handler =  (event, context, callback) => {
  //prevent timeout from waiting event loop
  callback(null, event);

};

我正在将URL输出为{}.

I am getting output as {} for the url.

注意:已启用Lambda代理集成.

Note: Lambda proxy integration is enabled.

推荐答案

应该在API网关上启用Lambda代理集成,以便API Gateway将事件详细信息(包括参数)传递给Lambda.

Lambda Proxy Integration should be enabled on the API Gateway in order for API Gateway to pass the event details, including the params, to Lambda.

有关如何在控制台中执行此操作的信息,请参见此处:

See this image here for how to do this in the console:

转到您的API,然后转到资源",再转到方法执行",然后选择集成请求".从那里勾选使用Lambda代理集成"框.

Go to your API, then your Resources, then your Method Execution, and then select "Integration Request". From there tick the box that says "Use Lambda Proxy Integration".

启用此功能后,API网关会将事件中可用的请求详细信息(包括参数)代理到Lambda.

Enabling this allows API Gateway to proxy the request to Lambda with the request details, including the params, available in the event.

这篇关于AWS Lambda nodejs函数中的事件对象为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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