Nodejs lambda函数在30秒后退出

时间:2017-10-12 01:35:48

标签: javascript node.js mongodb amazon-web-services lambda

30秒后lambda函数退出

Intend是以下函数应该在数据写入fire base db本地时触发该函数正常工作30秒但是当我在AWs中部署它时,该函数只是运行并停止(它不会等到数据是来自火灾基地db)

'使用严格的&#39 ;; var MongoClient = require(' mongodb')。MongoClient;

let atlas_connection_uri;
let cachedDb = null;

let firebase = require('firebase');

exports.handler = function(event, context,callback)
{
    // var uri = process.env['MONGODB_ATLAS_CLUSTER_URI'];
    var uri = "mongodb://dshan:1ew10is022@ds139904.mlab.com:39904/vishchatapp";
    context.callbackWaitsForEmptyEventLoop = false;
    firebase.initializeApp({
        serviceAccount: {},
        databaseURL: "https://harmanconnectedcar-180411.firebaseio.com/"
    });

    var starCountRef = firebase.database().ref('events' );
    starCountRef.on('value', function(snapshot) {
        console.log("*************snapshot*****snapshot*****************")
        console.log (snapshot.val()) ;
        if (atlas_connection_uri != null) {
            processEvent(event, context, callback,snapshot.val());
        }
        else {
            atlas_connection_uri = uri;
            console.log('the Atlas connection string is ' + atlas_connection_uri);
            processEvent(event, context, callback,snapshot.val());
        }
       /* context.succeed();*/
    });


};

function processEvent(event, context, callback,triggerData) {
    console.log('Calling MongoDB Atlas from AWS Lambda with event: ' + JSON.stringify(event));
   }

在AWS中将执行时间增加到最多一分钟,但仍然无法从AWS中的事件中获取数据请说明如何使该函数保持活动状态并将数据提供给db

0 个答案:

没有答案