DEV Community

WanjohiChristopher for AWS Community Builders

Posted on

Create,Connect,Configure Postgres on AWS Successfully with Python

I have seen many people have been struggling to connect with AWS Postgres. Here is a step by step guide.
Assuming you have already created an account on AWS, on the Console search "RDS" RDS meaning Relational Database Service.
Navigate to databases and click database as shown here:

Postgres

On the pop up choose Postgres, Free tier.

create database
Change the database identifier and create your own password for authentication in python.

DB IDENTIFIER
Remember to make sure the database is public and configure VPC security groups.
This is where you need to be careful. If you are using your company's laptop, the inbound rules will use ip address which might be closed so make sure it's not closed or use your own laptop to connect and use "my ip" or open all ports.

security groups

Once created lets now go to our python and connect using psycopg2.
The following code will connect to postgres successfully.

connection

host:

Endpoint on aws

database:

your database

user:

Postgres if default otherwise change to yours.

Password:

Db password

Thank you. Happy Learning

Top comments (0)