In this post, we explore a solution to the challenge of running the Rails console against a PostgreSQL database housed in a private subnet for security reasons. While it's a good security practice, it can limit access for bootstrapping users or debugging issues. By tunnelling through a Bastion server, we can establish a connection to the database as if it was running locally. We walk through code examples of SSH tunneling, database connection, and how to run Rails console. A key point is to ensure the Bastion server is shut down after use.
We're moving on and tightening our database security in step 3. We're running our database in private subnets within a created RDS instance on our VPC, making sure our data isn't accidentally left in the open. After setting up our network and security settings, we'll dive into creating our databases manually via our secure Bastion server. With a few commands, we set up our dev and prod databases, don them with strong passwords and grant them access to our master username. Voila, our RDS instance is ready to go! Stay tuned for step 4, where we unveil the real deal,...