1

I have a postgres RDS instance which my Node.js web application running on an EC2 instance is not able to connect to. The error in my EC2 node logs is: error: password authentication failed for user "ubuntu"

I can confirm that I have the right username, password, database name, etc because it is working correctly on the development build on my machine. I copied all the .env parameters exactly into my ec2 machine for the production build. When attempting to connect to RDS on my production application web page, it fails. I have restarted my Node.js server multiple times and have rebooted the whole ec2 machine. I have confirmed that the env variables are there with printenv.

What would you recommend trying to fix this issue?

EDIT for more details: My nodejs setup should be correct because my nodejs server will call some external APIs that do not require my postgres database and those calls work properly.

EDIT2: This is strange because my username for RDS is postgres, while my username for EC2 is ubuntu. I wonder if somehow there's some clash between env variables. I checked printenv but didn't find any though

EDIT3: See comments for my workaround.

1 Answer 1

1

I would suggest to test the database credentials by directly connecting to RDS database using psql client on EC2 instance.

Sign up to request clarification or add additional context in comments.

3 Comments

The issue ended up being that, for some reason, pg is trying to connect to RDS using the username ubuntu instead of postgres, even though my code specifies it should connect as user postgres. I think something is overriding this configuration, but I can't figure out what. I did end up implementing a hacky solution where I created a new user on my pg database called ubuntu and gave it r/w access, and this ended up working.
I tested and also saw I was using the wrong user before, overriten to use "ubuntu" instead of "postgres", however I'd like to find out how to stop overriting that and start using "postgres" ad default instead
I used this guide to connect with psql docs.aws.amazon.com/AmazonRDS/latest/UserGuide/… and this other to create a user with similar permissions that postgres default user docs.aws.amazon.com/AmazonRDS/latest/UserGuide/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.