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.