Not able to connect to AWS documentDb from Lambda

Viewed 2159

I'm trying to connect to AWS documentDB from Lambda function but, not able to connect.

MongoClient.connect never calls the callback function connected.

TLS is off on documentDB Cluster. I'm able to connect via mongo shell.

Lambda & documentDB are in same VPC & Security group.

'use strict';

module.exports.search = async (event, context, callback) => {

const MongoClient = require('mongodb').MongoClient;
const url = "mongodb://xxx:xxxx@xxx-db.cluster-xxx.us-east-2.docdb.amazonaws.com:27017";

console.log("Starting");

MongoClient.connect(url, 
    { 
        useNewUrlParser: true
    },
    function(err, client) {
        if(err)
            throw err;

        console.log("Connected");

        db = client.db('mydb');

        col = db.collection('mycollection');

        col.find({}).toArray().then(result => {
            console.log(result);
            return { statusCode: 200, body: result };
        }).catch(err => {
            console.log('=> an error occurred: ', err);
            return { statusCode: 500, body: 'error' };
        });

    });

};

Output only prints starting which was consoled before calling Mongo.Connect. How to identify or debug the issue ?

1 Answers
Related