简体   繁体   中英

org.postgresql.util.PSQLException: FATAL: database “<<database_name>>” does not exist, in the AWS java lambda

I am facing the error, org.postgresql.util.PSQLException: FATAL: database "" does not exist

Java code is deployed in AWS lambda to get connect the postgres database running in RDS.

Code

String jdbcUrl = "jdbc:postgresql://database-1.cfgz85wxhk0z.eu-west-1.rds.amazonaws.com:5432/postgres";

Connection connection = null;
try {
    connection = DriverManager.getConnection(jdbcUrl, "database_name", "Password");
    Statement st = connection.createStatement();
    st.execute("select * from <schema>.employee;");
} catch (SQLException e) {
    e.printStackTrace();
} catch(Exception e) {
    e.printStackTrace();
}

Strange as it sounds, that would indicated that there is no database called postgres in that database cluster.

Replace the last part of your JDBC URL with an existing database.

You should check that your Lambda function is configured to be connected to the same VPC of your RDS instance. Otherwise, they will not be able to communicate.

The official documentation provides more details as well as some tutorials/examples. You can also configure it manually in the AWS Lambda console (in the Configuration pane, under Network, near the bottom of the page). Finally, AWS has a knowledge base entry on how do I connect a Lambda function to a dedicated VPC?

https://www.reddit.com/r/aws/comments/a75gfw/database_does_not_exist_when_connecting_to/ Followed some suggestions from the above link. Issue resolved

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM