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 Tunneling via SSM Sessions: Establishes a secure tunnel through an SSM Session using the SSM plugin for the AWS CLI.
- 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 (
~/.rdst/tunnel_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:
rdst startrdst stoprdst statusrdst configrdst 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 | 🤷🏼♂️ |
🛒 Pre-requisites
For SSH Usage
- Ensure port 22 is accessible
For SSM Usage
- Ensure your EC2 instance role has the managed policy
AmazonSSMManagedInstanceCoreattached - Install the SSM-Agent on your instance
- Restart the service, in some cases it may need an instance reboot.
- Install the Session Manager plugin for the AWS CLI
🛠️ Installation
Recommended PyPi
pip install rds-tunnel
Homebrew
To install rds-tunnel using Homebrew, follow these two simple steps:
1. Tap the Repository
First, you need to "tap" this Homebrew repository. This tells Homebrew where to find the rds-tunnel formula.
brew tap sbekx/rds-tunnel
2. Install rds-tunnel
Once the tap is added, you can install the rds-tunnel package:
brew install rds-tunnel
3. (Potentially) Run brew link
You might see a message like "The formula built, but is not symlinked into /opt/homebrew", if so, run:
brew link --overwrite rds-tunnel
Homebrew will handle all the necessary dependencies and set up rds-tunnel in an isolated environment.
(Optional) Build it Locally
To run rds-tunnel locally, follow these steps:
-
Clone the Repository:
git clone https://github.com/sbekx/rds-tunnel.git cd rds-tunnel
-
Build the Package: Ensure you have
uvinstalled. Navigate to the root of the project and run:uv buildThis creates a distributable wheel file (e.g.,
rds_tunnel-1.0.0-py3-none-any.whl) in thedist/directory. -
Install the Package: Install the generated wheel file using
pip. This makes therdstcommand 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 ~/.rdst/tunnel_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
~/.rdst/tunnel_config.jsonfile.rdst config --fetch
-
Show the current config:
rdst config --show
-
Reset the config: This will reset your
~/.rdst/tunnel_config.jsonback 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,
"INSTANCE_ID": "i-XXXXXXXXXX",
"AWS_REGION": "us-east-1", # Set region
"AWS_PROFILE": "default" # Set profile for different environments
}
🚀 Usage
rdst start
Starts the SSH tunnel as a background daemon process. It will use the configuration from ~/.rdst/tunnel_config.json by default.
rdst start
After starting, the daemon's logs will be written to ~/.rdst/tunnel.log.
You can also specify a custom configuration file for advanced use cases:
rdst start --config-file /path/to/another_config.json
*By default all configs, logs, are stored in ~/.rdst/
rdst stop
Finds the running daemon process and sends a signal to gracefully shut it down.
rdst 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rds_tunnel-2.0.0.tar.gz.
File metadata
- Download URL: rds_tunnel-2.0.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47eb2d24c9f1ceb6d453067372dbf147298214dce4d30f911f4a9b6c1f84a3e5
|
|
| MD5 |
1e390fb80963fe86f1076ab26fb9ccb7
|
|
| BLAKE2b-256 |
be0bde6e9335650da525ae3e98ddb6f17d16221f12d8bc9d307fd065fcd750dc
|
Provenance
The following attestation bundles were made for rds_tunnel-2.0.0.tar.gz:
Publisher:
release.yml on sbekx/rds-tunnel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rds_tunnel-2.0.0.tar.gz -
Subject digest:
47eb2d24c9f1ceb6d453067372dbf147298214dce4d30f911f4a9b6c1f84a3e5 - Sigstore transparency entry: 622528293
- Sigstore integration time:
-
Permalink:
sbekx/rds-tunnel@10f5e54ef125b9a125b95a652e7e1d15b9fe89f1 -
Branch / Tag:
refs/tags/2.0.0 - Owner: https://github.com/sbekx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10f5e54ef125b9a125b95a652e7e1d15b9fe89f1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file rds_tunnel-2.0.0-py3-none-any.whl.
File metadata
- Download URL: rds_tunnel-2.0.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b08fc74f8ce19df3424eb4420e4edcde8f1448aa58f53ea028efd72ccfcf3d14
|
|
| MD5 |
c1ba9689dbc579b6eb4c274c3fb25279
|
|
| BLAKE2b-256 |
df54a17ae0c8cc2f33a222e61dc44b308e59b9734b517ebee87d6ac29b4e6bd1
|
Provenance
The following attestation bundles were made for rds_tunnel-2.0.0-py3-none-any.whl:
Publisher:
release.yml on sbekx/rds-tunnel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rds_tunnel-2.0.0-py3-none-any.whl -
Subject digest:
b08fc74f8ce19df3424eb4420e4edcde8f1448aa58f53ea028efd72ccfcf3d14 - Sigstore transparency entry: 622528295
- Sigstore integration time:
-
Permalink:
sbekx/rds-tunnel@10f5e54ef125b9a125b95a652e7e1d15b9fe89f1 -
Branch / Tag:
refs/tags/2.0.0 - Owner: https://github.com/sbekx
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10f5e54ef125b9a125b95a652e7e1d15b9fe89f1 -
Trigger Event:
workflow_dispatch
-
Statement type: