Playing with AWS RDS (#1)
Tags: aws, postgres, tutorial, beginners
Published: 2022-12-26 08:05:33

Let's start by creating our own VPC first.
It's quite easy with the new UI.
![New create VPC experience](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49kqh3d94zrxw5u2gx1i.png)
Use the 'Name tag auto-generation' feature to generate the name tag for all resources. For example, if I enter the value 'myvpc' as a Name tag, then each of the vpc resources would contain this phrase 'myvpc' in each their respective name tags.
![Name tags of VPC resources](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8srxtnlmeikvihcm9j6d.png)
Let's keep the no. of AZs, public and private subnets to 2 (as defaulted), NAT gateway in 1 AZ, and leave other attributes to their default values.
Click on the 'Create VPC' button now.
With this new create VPC UI experience, you can see the progress of each steps.
![Create vpc workflow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3d2iblr10t3ym7iappeg.png)

Now as the VPC is created, let's move to the RDS part.
I'm selecting postgres for this example.

![RDS Console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wshojdbpj7el5noazagx.png)

1. Click on the 'Create database' button.
2. Select 'PostgreSQL' as the DB engine. Let's use the default engine version populated (13.7-R1 for me).
3. Select Dev/Test as a template.
4. Select 'Single DB Instance' as deployment option which would create a single DB instance with no standby instances.
5. Now select the DB instance attributes like DB instance name, master username & password, DB instance class etc. ![DB instance attributes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/929yurquanecoq33mnie.png)
6. Select general SSD (gp2) as storage class with a 25 GB storage.
7. In the connectivity section, select the VPC that you created. Also, keep the 'Public access' to 'Yes' for us to connect to the DB through internet. 
8. Select 'Create new' for the VPC security group and provide a name for the new security group.
9. Lastly, provide a name for the initial database in the 'Additional configuration' section.
10. Leave other options to their default values, and click on the 'Create database' button.

Now the database is being created, it would take some time for up and running.

Meanwhile, let's download pgadmin (postgres admin tool) from https://www.pgadmin.org/download/. We would test the connectivity to our AWS RDS database using this pgadmin tool.
After the installation is completed, start the pgadmin tool. It would look something like the following.

![pgadmin](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/96c57zrfk051iefopa02.png)
We intend to setup the connection to our RDS database using pgadmin. For this, we first new our RDS endpoint. 
Hopefully, the RDS configuration is completed by this time and it is up and running. Go to the AWS RDS console, and check the status of the RDS instance.

![database instance status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfpqflhcc52eplxf9886.png)
Click on the DB identifier.

![database instance details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ene6cg3e3vn46yh5aesn.png)


Copy the endpoint shown under 'Connectivity & security' section.
Go to pgadmin. Right-click 'Servers'. Select Register->Server..
Provide a name to this connection.
Paste the endpoint information (copied earlier) in the 'Hostname/address' edit box and click on save.

![pgadmin endpoint](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5jr72xp5ya17v1inxdwd.png)

Once the connection is established, you can find the initial database that you created your postgres DB instance.

![postgres db](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bb8m9wmys01e5wa14qq7.png)

##Check the events created in RDS console##

![rds events](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v01te7rs3q3352psnr47.png)

##What would happen if we change the instance type for this Single AZ deployment##
Changing instance type from db.t3.micro to db.t3.small.
![modify instance type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n44pgri4hxosst703zx9.png)

Modification is in progress..
![modification in progress](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6puaa3ew32egi8uh9q8.png)

The corresponding events get logged and can be seen in the 'Logs & events' section. Note that DB instance was shut down and restarted after the change was applied. It generally takes 2-5 mins (based on my experience) for the DB instance to be up and running after the modification.

![db instance change](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qygyec11mc9dqt3xdl58.png)

##What would happen if we change the instance type for a multi-AZ deployment##
Let's first make our DB instance multi-AZ.
![multi-az](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9ysh975yplvh4qe1gdf.png)
Wait till the multi-AZ conversion is completed. ![muti az status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dy1a6k1wg7flm80nhyuc.png)

![muti-az events](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqtwchv41biiapt0k3g5.png)
Now, let's change back the instance type from db.t3.small to db.t3.micro.

![db instance type change](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nlbe69fllg4g8qlpy47v.png)

Note that the moment the DB instance was shut down, Multi-AZ instance failover started. And hence the DB instance came back to a running state quite fast.

![db ins type change events](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bbu7qu7p3v5391pcufz6.png)