如何在Lambda之外进行异步设置?

时间:2018-11-21 16:37:59

标签: aws-lambda

Config调用参数存储并返回一个config对象。我需要等待初始化mysql。

const config = require('./config');
const mysql = require('serverless-mysql')(config);

exports.handler = (event, context) => {
  // mysql stuff
}

1 个答案:

答案 0 :(得分:1)

我认为您需要等待这种情况发生?

const mysql = require('serverless-mysql')(config)??

如果是,则执行以下操作:

const config = require('./config');

async function mySQLStuff() {

  try{
    const mysql = await require('serverless-mysql')(config);
  } catch (error) {
    //handle error
  }
 return mysql;
};

exports.handler = (event, context) => {

  mySQLStuff()
    .then((data) => //mysql stuff)

};