How to connect easily to a private Amazon RDS without EC2 instances
Tags: aws, rds, route53, postgres
Published: 2021-05-15 13:27:06

### Disclaimer.

*My client owns its own domain, I haven't tested it without a domain. If you test it and worked as expected, share the trick in the comments section below.*

If you have been developing apps or are new to AWS, you might have experienced some challenges; especially, when you are running them under a **private subnet**.

A common tutorial is this one from AWS:

[How can I connect to a private Amazon RDS DB instance from a local machine using an Amazon EC2 instance as a bastion host?][1]

Generally speaking, it's overcomplicated. My client has some extreme policies that made the tutorial barely usable. We needed to do some extra workarounds in the AWS CLI to make it work, including opening the specific ports in advance (5432 [PostgreSQL], for instance). And finally connecting with an uncommon trick like this one:

> ssh -L localhost:MY_LOCAL_PORT:MY_LOCAL_URL:MY_DB_PORT -N -J MY_LOCAL_USER -i ~/MY_LOCATION/MY_FILE_NAME.pem VM_USER

After a while, I found an easier way that worked for us, we created a **Create private hosted zone** with our **domain** and our preferred **region** (*eu-west-1*) in **Route 53**, for example:

> 00027384723984729.eu-west-1.loc.supernova.com

Next, inside your hosted zone you need to create a new **record** using your **RDS instance endpoint**, for example:

> database-1.cwfas04jasa01.eu-west-1.rds.amazonaws.com

[![record][2]][2]

Your new record must contain the following:

- **Record name:** the name you want to give like **homedb**
- **Record type:** choose the option: **CNAME**.
- **Value:** the *endpoint* in your RDS instance: *database-1.cwfas04jasa01.eu-west-1.rds.amazonaws.com*

Do click in **Create records** and that's all. You will get something like this:

> homedb.00027384723984729.eu-west-1.loc.supernova.com

After this, you can access your RDS instance without any extra EC2s or complex workarounds. If you face any troubles, verify if you have the DB ports open in your firewall.

### Follow me on:

|  Personal  |  LinkedIn  |YouTube|Instagram|Cyber Prophets|Sharing Your Stories|
|:----------|:----------|:------------:|:------------:|:------------:|:------------:|
|[![Personal](https://raw.githubusercontent.com/FANMixco/federiconavarrete/master/img/favicons/favicon.png)](https://federiconavarrete.com)|[![LinkedIn](https://i.stack.imgur.com/idQWu.png)](https://www.linkedin.com/in/federiconavarrete)|[![YouTube](https://i.stack.imgur.com/CFPMR.png)](https://youtube.com/c/FedericoNavarrete)|[![Instagram](https://i.stack.imgur.com/PIfqY.png)](https://www.instagram.com/federico_the_consultant)|[![RedCircle Podcast](https://i.stack.imgur.com/4XICF.png)](https://redcircle.com/shows/cyber-prophets)|[![RedCircle Podcast](https://i.stack.imgur.com/4XICF.png)](https://redcircle.com/shows/sharing-your-stories)|

[![sponsor me](https://raw.githubusercontent.com/FANMixco/Xamarin-SearchBar/master/bmc-rezr5vpd.gif)](https://www.buymeacoffee.com/fanmixco)

_Banner credits:_

http://trekintech.com/backup-recovery-for-aws-rds/

  [1]: https://aws.amazon.com/premiumsupport/knowledge-center/rds-connect-ec2-bastion-host/#:~:text=Launch%20and%20configure%20the%20EC2%20instance&text=Select%20an%20Amazon%20Machine%20Image,gateway%20in%20its%20routing%20table.
  [2]: https://i.stack.imgur.com/NEyP4.png