How to Connect AWS Elastic Beanstalk with Supabase PostgreSQL Database for Easy Deployment

Last weekend, I decided to try out AWS and learn something new by setting up a simple REST API without a front-end in Go. Usually, I would use my go-to process with GCP, but this time I wanted to challenge myself. So, I turned to Elastic Beanstalk and discovered an entirely new way to approach my project.

Many articles discuss how to set up a simple Elastic Beanstalk REST API, but the most straightforward guide I found for go was TutorialEdge's video: Deploying A Go App to AWS Elastic Beanstalk

Although this approach got me quite far, I faced one major roadblock: I couldn't get the service to connect to my Supabase PostgreSQL database. It took some intensive research, but I eventually managed to figure it out. The biggest discovery and breakthrough came when I took the time to read through the documentation and discovered that Elastic Beanstalk was automatically setting up an EC2 instance. This realization was key in making the setup process surprisingly simple

Here are the steps I took:

  1. Identify the EC2 Instance.
  2. Find the security group associated with the EC2 instance and go to the "Inbound rules" tab.
  3. Add a new rule that allows traffic on the PostgreSQL port (5432) for the source IP addresses that require access, i used 0.0.0.0 which allows all. (Should probably update to be more secure).
  4. Specify the Supabase PostgreSQL database's hostname and port, username, and password in your application's configuration settings. This can be found back in the Elastic Beanstalk environment > Configuration > Software.

Overall, connecting Elastic Beanstalk to a Supabase PostgreSQL database is a relatively simple process. By following the steps outlined above, you can easily set up and manage your web applications on AWS using Elastic Beanstalk and Supabase.