🌈 ESP32-S3 Rainbow: ZX Spectrum Emulator Board! Get it on Crowd Supply →
View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

In a recent sequence of posts on deploying a Rails application to Elastic Beanstalk (Step1 is here) we set up a secure VPC with public and private subnets. Part of this secure setup is to place your PostgreSQL database server in the private subnets and not make it publicly accessible.

This is great from a security perspective, but raises the question - how do I run my rails console against the database? Typical reasons for doing this might be to bootstrap your users (e.g. create the first Admin user). Or for when you need to debug some data issue.

This post runs through how to tunnel through your Bastion server to your database.

To tunnel through to our database we use ssh:

ssh -i [IDENTITY_FILE] -L [LOCAL_PORT]:[RDS_HOST]:[RDS_PORT] ec2-user@[BASTION_HOST]

An example of what this command might look like is:

ssh -i DemoKeyPair.pem -L 6543:demo.c2syu2demiip.eu-west-1.rds.amazonaws.com:5432 [email protected]

This will create a port mapping through our bastion server from our local machine port 6543 to demo.c2syu2demiip.eu-west-1.rds.amazonaws.com port 5432.

Once this is successfully set up we can connect to our database as if it was running locally:

psql -h localhost -p 6543 -U db_user -d demo

And to run our rails console (assuming you have setup your production database yml to use DATABASE_URL):

DATABASE_URL=postgres://db_user:Y509q2XJ8M@localhost:6543/demo DISABLE_SPRING=1 bundle rails console production

One important thing to note - DISABLE_SPRING=1 - this is necessary as otherwise spring will bring up the console with the cached environment from previous runs. This can lead to you connecting to the develop database or to errors if you don’t have PostgreSQL running locally:

	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

As always, once you are finished doing what needs to be done with the database, make sure you shutdown your Bastion server. Ideally it should only be run on an as needed basis.

Related Posts

Step 3 - Configure RDS: Deploying a Rails Application to Elastic Beanstalk - 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, deploying a Rails app.
.Net Core and PostgreSQL on the Mac - In this blog post, we look at how to connect .NET Core's Web API with PostgreSQL on a Mac platform. We go through step-by-step instructions including setting up a new .NET project and creating a Web API, installing and using dotnet command line, installing required packages, setting up a PostgreSQL database, configuring the .csproj file, creating and integrating a database connection, and defining test entities and required methods for our API. The post also guides through the process of using the API to create, retrieve, and delete database entries. Overall, it shows how Microsoft is making strides in allowing cross-platform development with .NET Core and PostgreSQL.
Step 1 - Setup VPC: Deploying a Rails Application to Elastic Beanstalk - In this blog post, I am guiding you through the process of deploying a Rails application to Elastic Beanstalk in a Virtual Private Cloud (VPC) on Amazon AWS. I detail the setup of a VPC, subnets, and internet gateways, as well as the configuration of NAT gateways and security groups. Ultimately, this will allow for a safe, internet-accessible environment for your application and its accompanying databases.
Step 2 - Setup Elastic Beanstalk: Deploying a Rails Application to Elastic Beanstalk - In this post, I describe how to set up, configure and deploy an Elastic Beanstalk application on a VPC in Amazon AWS, using Rails 5 and Ruby, using Puma for deployment and configuration of Public and Private subnets in Elastic Load Balancer. I also cover the details of network card settings, the selection process for subnets and security groups for Load Balancer and Instances, and finally shared the result of deploying the sample application on Elastic Beanstalk.

Related Videos

ESP32 Remote Logging - Learn how to remotely monitor your Arduino devices by sending log messages to a central server using UDP and a paper trail. Get insights into how your hardware is performing, even when you can't physically access it.
Forget the Arduino Serial Plotter - try this instead! - Hey everyone! So, you're probably familiar with the Arduino serial plotter, right? It's useful for basic stuff, but I wanted something better, more cross-platform, and runs right in the browser. Enter the web serial plotter, using the web serial API! It's super flexible with zoom, export options, and light/dark mode. You can even pan through history or switch to absolute time. Plus, it's all secure and runs locally. It's open source, and I'd love your contributions or bug reports on GitHub. It's still a work in progress, but I think you'll find it pretty handy!
ESP32-S3 - Which Pins Are Safe To Use? - In this video, I've decided to dive deep into the ESP32-S3, a module ruling my lab recently due to its plug-in-and-play functionality, and the flexibility offered by its GPIO matrix. However, working with it requires vigilance, especially with regard to the strapping pins and USB data pins, among others. Discovering such quirks, I've encountered unexpected values, short glitches and the occasional code crash. To help you avoid these bumps, I've documented everything I've learned on my GitHub repo, where I'm inviting you, my fellow makers and engineers, to contribute your valuable experiences and findings. After a minor hiccup with my ESP32-TV, expect an updated PCB design, courtesy of PCBWay. Explore the ESP32-S3 with me, and let's unravel its secrets together, one pull request at a time.
TensorFlow Lite With Platform.io and the ESP32 - Learn how to train a simple TensorFlow Lite model and run it on the ESP32 using PlatformIO! With clear instructions and a helpful video, this tutorial will have your project up and running in no time.
Unlocking the Power of ChatGPT: Effortlessly Generate Arduino Code for Your Projects! - Witness ChatGPT's impressive potential for generating working Arduino code, as demonstrated in a step-by-step ESP32-based project utilizing a potentiometer and dot star LED.
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts