Setup a SSH tunnel
Often you need to migrate production data back to your development environment.In our case we use virtual private networks with strict private- and public subnets in order to secure our infrastructure, e.g. access to the database or hotfixing something via a remote shell (keep 12-factor's admin processes in mind).However, that makes accessing production data quick and easily (so no developer unfriendly RDS snapshot S3 transfers) hard as we can't access a resource in a private subnet from the outside.Gladly we have something called bastion hosts with gives us a helping hand.In the example below we have a postgres database running on a RDS instance in a private subnet. On the other hand we have a tiny EC2 instance in a public subnet which accepts incoming traffic over SSH (port 22) retricted to our IP address. The same instance (the bastion host) is allowed to access the database in the private subnet.
Often you need to migrate production data back to your development environment.
In our case we use virtual private networks with strict private- and public subnets in order to secure our infrastructure, e.g. access to the database or hotfixing something via a remote shell (keep 12-factor's admin processes in mind).
However, that makes accessing production data quick and easily (so no developer unfriendly RDS snapshot S3 transfers) hard as we can't access a resource in a private subnet from the outside.
Gladly we have something called bastion hosts with gives us a helping hand.
In the example below we have a postgres database running on a RDS instance in a private subnet. On the other hand we have a tiny EC2 instance in a public subnet which accepts incoming traffic over SSH (port 22) retricted to our IP address. The same instance (the bastion host) is allowed to access the database in the private subnet.
Now let's setup a SSH tunnel:
ssh -L 8001:yourendpointhere.eu-west-1.rds.amazonaws.com:5432 ubuntu@<public_ip_bastion_host>
Once setup your SSH tunnel you are able to e.g. create database backups easily to your local machine:
pg_dump -Fc -v -h localhost -p 8001 -U [master username] [database] > [database].dump
Using Django you are also able to run your local code in the remote shell (using the django-environ library):
DATABASE_URL=postgresql://postgres:xxx@localhost:8001/[database] python manage.py shell
Over de auteur
Rob Moorman
Iets aan gehad? Deel het artikel.
Andere artikelen
Bekijk alle artikelen-
Werk sneller met herbruikbare content in Vio
Als contentbeheerder wil je snel kunnen werken, zonder concessies te doen aan kwaliteit of consistentie. Lees er meer over in ons blog.
-
Geen plugins, wel alles wat je nodig hebt
Als contentbeheerder wil je snel kunnen werken, zonder concessies te doen aan kwaliteit of consistentie. Lees er meer over in ons blog.
-
Maak sneller betere content met de Vio AI app
Maak, corrigeer of redirigger sneller betere content met de Vio AI app. Lees er meer over in ons blog.
-
Vio vs Wordpress: een eerlijke vergelijking
WordPress is een van de bekendste CMS’en. Vio zich onderscheidt met gebruiksvriendelijkheid, veiligheid en schaalbaarheid. Lees er meer over in ons blog.
-
5 tips om je website optimaal te beveiligen
Datalekken en cyberaanvallen kunnen enorme gevolgen hebben. Vio maakt het eenvoudig om je website optimaal te beveiligen. Lees er meer over in ons blog.
-
7 Signalen dat jouw CMS dringend toe is aan vervanging
Herken je één of meer van deze signalen? Dan is het tijd voor een upgrade. Lees er meer over in ons blog.
-
Waarom updates essentieel zijn voor je website
Het up-to-date houden van een website blijft voor veel bedrijven een uitdaging. Waarom het toch essentieel is? Lees er meer over in ons blog.
-
Vio, een duurzaam en toekomstbestendig CMS
Wat maakt Vio een duurzame en toekomstbestendige keuze voor jouw organisatie? Lees er meer over in ons blog.
-
Gebruiksvriendelijkheid: essentieel voor elke organisatie
In een wereld waar snelheid en eenvoud de norm zijn, is een gebruiksvriendelijk CMS de basis voor succes. Lees er meer over in ons blog.
-
Fix Docker no space left on device
When doing a lot with Docker locally every developer find themselves with the no space left on device error message. Even though the error doesn't occur it's good to often …
Rob Moorman
-
Squash Django migrations
Maintaining a Django (and Wagtail) platform over multiple years comes with some challenges. Although Django is build to scale there are some things to consider while keeping your codebase clean. …
Rob Moorman
-
Migrating Wagtail ModelAdmin to the new snippet admin views
With the new snippet admin views the usage of modeladmin becomes outdated. The snippets now leverage the preview & history abilities from Wagtail, similar to the workflow of pages:PreviewDraft & …
Rob Moorman
-
Add Plausible to your Terraform CloudFront distribution
At Vicktor we take data very serious, that's why we have fully adopted Plausible as a simple and privacy-friendly Google Analytics alternative."Plausible is lightweight and open source web analytics. No …
Rob Moorman
-
Beautiful asserts with your Django Test Client
When you write tests using the [Django Test Client](https://docs.djangoproject.com/en/4.1/topics/testing/tools/#the-test-client) you often want to check for error messages being displayed correctly, or if a page renders specific HTML elements.
Rob Moorman
-
Structural pattern matching with Python 3.10 (AKA "Switch/Case")
Python has been designed to be a very readable and compact programming language [since the language was born in 1991](https://en.wikipedia.org/wiki/Python_(programming_language)). Indentation is required, semicolons are not needed, readability and elegance …
Rob Moorman
-
A Private PyPI server with AWS CodeArtifact
IntroductionWhen you develop a variety of reusable Python packages or apps you soon will be facing the limits of git dependencies. And you don't want to release company / project …
Rob Moorman