Node.js 在Lambda上查询mysql时任务超时

Node.js 在Lambda上查询mysql时任务超时,node.js,amazon-web-services,aws-lambda,amazon-lex,Node.js,Amazon Web Services,Aws Lambda,Amazon Lex,我一直在使用amazon Lex和Lambda与nodejs。我的问题是,当我尝试mysql查询时,lambda超时并且不向Lex返回任何结果 我需要帮助。 这是我的密码 'use strict'; const lexResponse = require("../helper/responseBuilder"); const db = require('../config/db') function dialog (intentRequest, callback) { const

我一直在使用amazon Lex和Lambda与nodejs。我的问题是,当我尝试mysql查询时,lambda超时并且不向Lex返回任何结果

我需要帮助。 这是我的密码

'use strict'; 
const lexResponse = require("../helper/responseBuilder");
const db = require('../config/db')

function dialog (intentRequest, callback) {

    const source = intentRequest.invocationSource;
    const userId = intentRequest.userId;
    const sessionAttributes = intentRequest.sessionAttributes || {};

    if (source === 'DialogCodeHook') {
        if (!companyRules) {
            getList(1, (results) => {
                console.log(results);
                callback(lexResponse.elicitSlot(
                    sessionAttributes,
                    intentRequest.currentIntent.name,
                    intentRequest.currentIntent.slots,
                    "Info",
                    { contentType: 'PlainText', content: results.name }
                ));
            });
            return;
        }
    }

    callback(lexResponse.close(intentRequest.sessionAttributes, 'Fulfilled',
    { contentType: 'PlainText', content: `Thanks` }));
}

function getList(data, callback)
{
    db.connection.getConnection( (err, connection) => {
        let statement = 'select `name` from tablename where id = ?';
        connection.query(statement, [data], (error, results, fields) => {
            if (error) throw error;
            connection.release();
            callback(results[0]);
        });
    });
}

function dispatch(intentRequest, callback) {
    console.log(`dispatch userId=${intentRequest.userId}, intentName=${intentRequest.currentIntent.name}`);

    const intentName = intentRequest.currentIntent.name;

    // Dispatch to your skill's intent handlers
    if (intentName === 'myIntent') {
        return dialog(intentRequest, callback);
    }
    throw new Error(`Intent with name ${intentName} not supported`);
}

exports.handler = (event, context, callback) => {
    try {
        process.env.TZ = 'America/New_York';
        console.log(`event.bot.name=${event.bot.name}`);
        dispatch(event, (response) => callback(null, response));
    } catch (err) {
        callback(err);
    }
};
这是我从cloudwatch得到的日志

11:34:14
2017-05-29T11:34:14.902Z    be549f47-4462-11e7-8d4a-e149b3395e95 event.bot.name=MyBot

11:34:14
2017-05-29T11:34:14.902Z    be549f47-4462-11e7-8d4a-e149b3395e95    dispatch userId=iv3an8pf9wmwtechg9gztkzlmtvwuanr, intentName=MyIntent

11:34:16
2017-05-29T11:34:16.146Z    be549f47-4462-11e7-8d4a-e149b3395e95     RowDataPacket { name: 'my name' }

11:34:17 END RequestId: be549f47-4462-11e7-8d4a-e149b3395e95

11:34:17
REPORT RequestId: be549f47-4462-11e7-8d4a-e149b3395e95  Duration: 3002.10 ms    Billed Duration: 3000 ms Memory Size: 128 MB    Max Memory Used: 25 MB

11:34:17
2017-05-29T11:34:17.904Z be549f47-4462-11e7-8d4a-e149b3395e95 Task timed out after 3.00 seconds
我还增加了超时配置,但我认为这不是问题所在


谢谢。

添加以下内容作为处理程序函数的第一行:

context.callbackWaitsForEmptyEventLoop = false;

但是当我决定也使用dynamo db时,context.callbackaitsforeptyeventloop必须设置为true,如何同时使用mysql和dynamo db?@FebriPratama目前dynamo db不支持vpc。因此,如果您是lambda,并且正在与rds通话,并且处于vpc中,则它也无法与dynamodb通话。dynamodb专有网络支持最近已进入私人测试阶段。