Skip to main content

Simple SSH Tunnel tool for connecting to RDS. Supports MySQL and PostgreSQL.

Project description

🚀 RDS Tunnel

A simple command-line interface (CLI) tool designed to establish and manage SSH tunnels to Amazon RDS (Relational Database Service) instances. This tool runs as a background daemon, allowing you to set up a secure connection and leave it running.

Project Background

This tool was created to provide a free and open-source solution to a common developer workflow: securely connecting local applications to a database inside a private network.

While many excellent database extensions exist for editors like VSCode, they sometimes require a premium subscription to share the tunnel connection both inside and outside the editor, rds-tunnel offers a different approach. By running as a standalone background process, it creates a single, persistent tunnel that any application on your system—your IDE, database GUI, or scripts—can use simultaneously.

The primary motivation behind this tool was the desire to seamlessly test Lambda functions locally against various database environments, from development to production.

Initially, this involved manually executing and maintaining a lengthy SSH command:

ssh -N -L 3306:RDS-DATABASE.cluster-********.us-east-1.rds.amazonaws.com:3306 ec2-user@EC2_HOST_IP_OR_PUBLIC_DNS -i /PATH/TO/KEY.pem

After this it became a simple script that I ran as an alias via my .zshrc. This then evolved as my development itch took hold and it became v0.1.0 a simple python script which takes a couple of arguments to start/stop the tunnel.

Now the CLI tool starts/stops the tunnel and runs in the background, it allows any code I run to interact with the DB over the ssh tunnel that's bound to my local.


✨ Features

  • Secure SSH Tunneling: Establishes a secure tunnel through an SSH bastion host to your RDS instance.
  • Daemonized Process: Runs the SSH tunnel in a separate background process, allowing you to start it and forget it.
  • Simple JSON Configuration: Uses a straightforward JSON file (~/.rdstunnel_config.json) for all settings.
  • Interactive Configuration: Interactively fetch credentials from AWS Secrets Manager to set up your configuration file.
  • Full CLI Control: Manage the tunnel with a clear and simple command structure:
    • rds-tunnel start
    • rds-tunnel stop
    • rds-tunnel status
    • rds-tunnel config
    • rds-tunnel help

Supported OS

I have tried to keep the tool as OS agnostic as possible, however 🤷🏼‍♂️ still applies to everything other Mac.

Name Status
Mac
Raspberry Pi 🤷🏼‍♂️
Ubuntu 🤷🏼‍♂️
Windows 🤷🏼‍♂️

🛠️ Installation

Recommended

pip install rds-tunnel

(Optional) Build it Locally

To run rds-tunnel locally, follow these steps:

  1. Clone the Repository:

    git clone https://github.com/sbekx/rds-tunnel.git
    cd rds-tunnel
    
  2. Build the Package: Ensure you have uv installed. Navigate to the root of the project and run:

    uv build
    

    This creates a distributable wheel file (e.g., rds_tunnel-1.0.0-py3-none-any.whl) in the dist/ directory.

  3. Install the Package: Install the generated wheel file using pip. This makes the rdst command available system-wide.

    pip install dist/rds_tunnel-*.whl # Adjust filename if different
    

⚙️ Configuration

The rds-tunnel tool uses a single configuration file located at ~/.rdstunnel_config.json.

On the first run, the tool will automatically create this file for you from a default template. You can then manage it using the rdst config command.

rdst config

This is the primary way to manage your settings.

  • Fetch config from AWS: This command will interactively prompt you for an AWS Secrets Manager secret name and region. It will then fetch the secrets and save them to your ~/.rdstunnel_config.json file.

    rdst config --fetch
    
  • Show the current config:

    rdst config --show
    
  • Reset the config: This will reset your ~/.rdstunnel_config.json back to the original default values.

    rdst config --clean
    

Example defaults.json

Your configuration file will need the following keys:

{
  "SSH_HOST": "your-ssh-bastion-host-ip",
  "SSH_USER": "ec2-user",
  "SSH_PRIVATE_KEY_PATH": "/path/to/your/ssh/private/key.pem",
  "DB_HOST": "your-rds-database-endpoint",
  "DB_PORT": 3306,
  "DB_USER": "your-db-username",
  "DB_PASSWORD": "your-db-password",
  "DB_NAME": "your-database-name",
  "LOCAL_PORT": 3306
}

🚀 Usage

rdst start

Starts the SSH tunnel as a background daemon process. It will use the configuration from ~/.rdstunnel_config.json by default.

rdst start

After starting, the daemon's logs will be written to ~/.rdstunnel.log.

You can also specify a custom configuration file for advanced use cases:

rdst start --config-file /path/to/another_config.json

rds-tunnel stop

Finds the running daemon process and sends a signal to gracefully shut it down.

rds-tunnel stop

rdst status

Checks if the tunnel is running and attempts to connect to the database to verify its status.

 rdst status
Tunnel: Active
Database: Connected
  - Bound to: 127.0.0.1:3306

rdst help

Displays a list of all commands and their options.

rdst help

🤝 Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rds_tunnel-1.0.1rc2.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rds_tunnel-1.0.1rc2-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file rds_tunnel-1.0.1rc2.tar.gz.

File metadata

  • Download URL: rds_tunnel-1.0.1rc2.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rds_tunnel-1.0.1rc2.tar.gz
Algorithm Hash digest
SHA256 296ac897a09bf4a0fe1b3f0710cb7c3f014882f6c0c818e07309fb15d02e397d
MD5 1d5ce29defd8598e47e1e384f9187f56
BLAKE2b-256 44d663a5b1558e7ffeb80cfd9fc558e6b4a45c0ee2e56c8d59400fa093a7949a

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds_tunnel-1.0.1rc2.tar.gz:

Publisher: release.yml on sbekx/rds-tunnel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds_tunnel-1.0.1rc2-py3-none-any.whl.

File metadata

  • Download URL: rds_tunnel-1.0.1rc2-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rds_tunnel-1.0.1rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 8ed83dc69d790e4faa77ed0fadacd4a1b2547de49522a00f6e6befd08d11ece7
MD5 a87cfbd6a3fffa17b1dc60ea6be5b59a
BLAKE2b-256 07bd55c283de474d12eaf1e4f763557f80631387390553b7137f3cd88ab0fa83

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds_tunnel-1.0.1rc2-py3-none-any.whl:

Publisher: release.yml on sbekx/rds-tunnel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page