Home:ALL Converter>unable to connect to AWS RDS postgresql database from AWS lambda

unable to connect to AWS RDS postgresql database from AWS lambda

Ask Time:2017-04-15T19:46:51         Author:Rohit

Json Formatter

I am working on an application where i want to connect to postgresql database from AWS lambda.I have setup the database with Publicly Accessible property set as true.Inbound and outbound policies are enter image description here

enter image description here

I am able to access the database through pgAdmin client but not able to do so through aws lambda.I have also associated AWSRDSFULLACCESS policy to lambda role and added vpc and subnet and security groups information to the advanced settings section.

I am getting following timeout error errorMessage": "2017-04-15T11:26:05.163Z 4ac2cf66-21ce-11e7-a6da-a7d26945c336 Task timed out after 9.00 seconds"

Node.js code I am using to connect to RDS is

var pg = require("pg");
exports.handler = (event, context, callback) => {
    // TODO implement
    const connectionStr = "pg://username:password@hostendpoint:5432/database name";
  var client = new pg.Client(connectionStr);
  client.connect(function(err){
    if(err) {
      callback(err)
    }
    callback(null, 'Connection established');
  });
};

How can I access the RDS from AWS Lambda?

Author:Rohit,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/43425662/unable-to-connect-to-aws-rds-postgresql-database-from-aws-lambda
yy