在lambda中部署Node-expressjs应用程序 - [错误:套接字挂断]代码:ECONNRESET

时间:2016-12-16 06:26:38

标签: node.js mongodb express lambda

我正在尝试将我的Expressjs应用程序部署到lambda中,但是我遇到了错误。请尝试我解决此错误。

lambda响应:

{
  "statusCode": 502,
  "body": "",
  "headers": {}
}

lambda log(它包含mongo连接和错误的控制台)

NativeConnection {
  base: 
   Mongoose {
     connections: [ [Circular] ],
     plugins: [],
     models: { Student: [Object] },
     modelSchemas: { Student: [Object] },
     options: { pluralization: true } },
  collections: 
   { student: 
      NativeCollection {
        collection: [Object],
        opts: [Object],
        name: 'student',
        collectionName: 'student',
        conn: [Circular],
        queue: [],
        buffer: false,
        emitter: [Object] } },
  models: 
   { Student: 
      { [Function: model]
        hooks: [Object],
        base: [Object],
        modelName: 'Student',
        model: [Function: model],
        db: [Circular],
        discriminators: undefined,
        schema: [Object],
        collection: [Object],
        Query: [Object],
        '$__insertMany': [Function],
        insertMany: [Function] } },
  config: { autoIndex: true },
  replica: false,
  hosts: null,
  host: '1.0.0.0.0',
  port: 3000,
  user: undefined,
  pass: undefined,
  name: 'sudentdb',
  options: 
   { mongos: {},
     db: { safe: true, forceServerObjectId: false },
     auth: {},
     server: { socketOptions: {}, auto_reconnect: true },
     replset: { socketOptions: {} } },
  otherDbs: [],
  _readyState: 1,
  _closeCalled: false,
  _hasOpened: true,
  _listening: false,
  db: 
   EventEmitter {
     domain: null,
     _events: 
      { close: [Function],
        error: [Function],
        reconnect: [Function],
        timeout: [Function],
        open: [Function],
        parseError: [Function] },
     _eventsCount: 6,
     _maxListeners: undefined,
     s: 
      { databaseName: 'studentdb',
        dbCache: {},
        children: [],
        topology: [Object],
        options: [Object],
        logger: [Object],
        bson: {},
        authSource: undefined,
        readPreference: undefined,
        bufferMaxEntries: -1,
        parentDb: null,
        pkFactory: undefined,
        nativeParser: undefined,
        promiseLibrary: [Function: Promise],
        noListener: false,
        readConcern: undefined },
     serverConfig: [Getter],
     bufferMaxEntries: [Getter],
     databaseName: [Getter],
     _listening: true },
  _events: 
   { connected: [Function],
     error: [Function],
     disconnected: [Function] },
  _eventsCount: 3 }

{ [Error: socket hang up] code: 'ECONNRESET' }

student.model.js

    var mongoose = require('mongoose'),
        Schema = mongoose.Schema;

    var studentSchema = new Schema({
        name: String,
        rollnumber: Number,
    },{collection:"student"});

module.exports = mongoose.model('Student', studentSchema);

api / student(REST API - GET方法)

exports.index = function(req, res) {

  console.log(mongoose.connection)

   Student.findOne({},function(err,doc){
       if(err){
          return res.json("error found"); 
       }else{
          return res.json(doc);
       }
   });

};

lambda.js

'use strict'
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./bin/www');
const server = awsServerlessExpress.createServer(app);


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

   console.log("EVENT: " + JSON.stringify(event));
   awsServerlessExpress.proxy(server,event,context);

}

0 个答案:

没有答案