Create A (Postgresql) Database with Amazon RDS
Tags: aws, postgres, database, cloudskills
Published: 2022-07-14 01:00:04

You might ask yourself, what is Amazon RDS? Types of Amazon RDS you can choose from ? Why use Postgresql?

On this article we would not just answer these questions, but also run a lab walkthrough on how to set this up on the cloud and on your local computer.


![Is everyone ready?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jd47p72b5s0kfvdf6t1p.gif)

### What is Amazon RDS?
Amazon RDS stands for Amazon Relational Database Service, it is a collection of managed services that makes it simple to set up, operate, and scale databases in the cloud.

### Types of Amazon RDS you can choose from
AWS give you seven popular engines to choose from, in no particular order:

- PostgreSQL
- MariaDB
- MySQL
- SQL Server
- Amazon Aurora with MySQL compatibility
- Amazon Aurora with PostgreSQL compatibility
- and Oracle

### Why use Postgresql?
PostgreSQL comes with many features aimed to help developers build applications, administrators to protect data integrity and build fault-tolerant environments, and help you manage your data no matter how big or small the dataset.

With all that said, let get to the lab.
![Kelvin Hart](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ex9v52iufxfmmm9d2fzd.gif)


### Step 1
Login to your AWS Console, click on services, on the top right corner. Click on **Database** > **RDS**

![AWS Navigation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/al7rxqagmpk3q46sxb8e.JPG)

### Step 2
On the RDS landing page, click on **Create database**.
This would direct you to the RDS Database dashboard.
On the dashboard, click on **Create database**

![Amazon RDS create database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3sb64vfmv9yb07nhdee.JPG)

![Amazon RDS create database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zytwtcnfn6axuy390lca.JPG)

### Step 3
**Database Method/Engine options**
For database creation method, select **standard create**.
For Engine option, select **PostgreSQL**.
For version, select your most preferred option depending on your use case, or just leave the default.

In this case, I would be using **PostgreSQL 13.4-R1**


![Data base engine option](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezaqmrv8v1jq3onjend8.JPG)

### Step 4 
**Templates**
In the template section, select **Free tier**

![Template](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4gu1l5x5ev8jkeuaqdfp.JPG)

### Step 5 Availability and durability
leave as default

### Step 6 
**Settings**
DB instance identifier, input **postgres**
Credentials Settings > Master username, use your preferred username, in my case, I would be using _skywalker_ , insert your password, and confirm password.

![DB settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qtqslesoploxmhndoco.JPG)

### Step 7 
**Instance configuration**
DB instance class, Burstable classes (includes t classes) is selected by default. select **db.t3.micro**

![Instance Configuration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qn8dr7ukkf2ok8tzmmo2.JPG)

### Step 8 
**Storage**
Storage type > General Purpose SSD (gp2)
Allocated storage > 5GB.
Leave everything else on the storage section as default

![DB Storage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g53tinxclybz1q455gik.JPG)



### Step 9 
**Connectivity**
Virtual private cloud (VPC) > select the default vpc or create a new vpc.
Subnet group > select default subnet or use created subnet.
Public access > Yes
VPC security group > choose existing or create new, if you haven't created one before.
Select Existing VPC security groups.
Leave Availability Zone as No preference.

![Amazon RDS Connectivity](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j22wwm8ar42hylk511do.JPG)

### Step 10 
**Database authentication**
Database authentication options > select Password authentication.
Click **Create Database**

You have successfully created a Postgres Database, using the Amazon RDS service on the AWS console.

### Step 11 
**Edit Inbound Security Rules**
After creating the database you would be redirected to the database dashboard.

Scroll down to the connectivity & security section.
Under security, click on the VPC security groups.

![VPC security groups](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1sj8ai8xd53eoa4e3pk.JPG)

When you click on the security groups, it would redirect you to EC2 > Security groups.

![Security group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8dil129kf8ciwdhr78q8.JPG)

click on the security group > click on inbound rules and edit it to the below configuration.

![edit inbound rules](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ipebiefdqujgf7die2i5.JPG)
Type should be PostgreSQL, on port 5432, IP 0.0.0.0/0 and ::/0

#### Now lets access our database on using Postbird.
If you don't already have Postbird installed, you can download it [here](https://www.postgresql.org/download/)

Now, launch Postbird, input your credentials, use your newly created database endpoint as host. set Port to **5432**.
Insert your username and password. leave Database and Start Query empty.
Click on **Test Connection**, if it returns Successfully connected, then click on **save & connect**. 

![Postbird connection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xoazj4fr17h1k8ypwezb.JPG)

You should be redirected to an interface that looks like this.
![Postbird GUI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggekersytohfmknlqjd2.JPG)

Thats not all, we need to be able to access the database using the AWS CLI on the terminal.




Firstly, we need to install psql, if you don't have it installed already, you can get it [here](https://www.timescale.com/blog/how-to-install-psql-on-mac-ubuntu-debian-windows/)

Open your terminal, use the following command template.

`psql -h yourRdsEndpointUrl -U skywalker postgres`

Example:
```
psql -h postgres.cwunlr23syoo.us-east-1.rds.amazonaws.com -U skywalker postgres
```

> Note: Change yourRdsEndpointUrl, with your original endpoint url.
change skywalker to your username.

Lets explain the above command line.
psql calls the postgresql command, -h means Host, then you insert your RDS endpoint. -U means user, the postgres, is the database name.

After you have entered the above command, if all your credentials are correct, you should have access to the postgres cli.

Enter this command to view a list of databases

```
\list
```


![psql cli](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d8kpw1lugttza3zmo81b.JPG)

We have successfully created a postgresql, resource on the cloud, using the Amazon RDS service.
We also installed, Postbird, inputted the appropriate credentials to access the cloud hosted database using Postbird GUI.

Went a step further to install the psql CLI on our local machine, inputted the correct credentials to access our newly created database, in our terminal.

If this article has helped you gain insight on Amazon RDS (postgresql), please like, share and subscribe.

Thank you.