aws-ssm-bridge
A Rust library implementing the AWS Systems Manager (SSM) Session Manager protocol with Python bindings.
⚠️ Disclaimer
This project is not affiliated with, endorsed by, or sponsored by Amazon Web Services, Inc. or any of its affiliates.
This is an independent implementation of the SSM Session Manager protocol.
Overview
Unlike the official AWS Session Manager Plugin (a CLI binary written in Go), aws-ssm-bridge is a library designed for embedding in your applications.
Features
- Binary Protocol: Full 120-byte AWS header, SHA-256 digest checking (advisory — mismatches warn but do not fail the session, to handle known SSM agent quirks)
- Reliable Delivery: Sequence tracking, ACK/retransmission, RTT estimation (Jacobson/Karels)
- Bounded Writer Channel: Dedicated writer task with backpressure — no mutex contention, no OOM under slow remotes
- Dead Connection Detection: Pong-based heartbeat with auto-shutdown on missed responses
- Interactive Shell: Raw terminal mode, resize handling (SIGWINCH)
- Port Forwarding: TCP tunneling via
PortForwarder - Python Bindings: Async support via PyO3, type stubs included
- Security:
#![forbid(unsafe_code)], zeroize token scrubbing, rate limiting, SSRF protection, target validation
Installation
Rust
[]
= "0.4"
= { = "1", = ["full"] }
Python
Quick Start
Interactive Shell
use ;
async
Programmatic Session
use ;
use StreamExt;
async
Port Forwarding
use SocketAddr;
use Arc;
use ;
async
Python
= await
await
=
Type-Safe Documents
Use type-safe document wrappers instead of magic strings:
use ;
// Port forwarding to instance (remote port 3306)
let session = new
.document
.build.await?;
// Port forwarding through bastion to RDS
let session = new
.document
.build.await?;
// SSH over Session Manager
let session = new
.document
.build.await?;
// Interactive command execution
let session = new
.document
.build.await?;
Documentation
Examples
Rust Examples (examples/)
| Example | Description |
|---|---|
interactive_shell.rs |
Full interactive shell with raw mode, resize, signals |
shell_session.rs |
Programmatic shell session (send commands, read output) |
port_forwarding.rs |
TCP port forwarding through SSM |
session_pool.rs |
Managing multiple concurrent sessions |
reconnecting.rs |
Auto-reconnection with exponential backoff |
metrics_session.rs |
Session with observability hooks |
Run with: cargo run --example interactive_shell -- i-0123456789abcdef0
Python Examples (python_examples/)
| Example | Description |
|---|---|
interactive_shell.py |
Full interactive shell with raw terminal mode |
shell_session.py |
Basic shell session with context manager |
port_forwarding.py |
TCP port forwarding |
multiple_sessions.py |
Concurrent sessions to multiple instances |
Run with: python python_examples/interactive_shell.py i-0123456789abcdef0
Architecture
src/
├── lib.rs # Public API
├── binary_protocol.rs # 120-byte header, SHA-256
├── session.rs # Session lifecycle, target validation
├── connection.rs # WebSocket, bounded writer task, retransmit, heartbeat
├── channels.rs # BroadcastStream-backed output multiplexer
├── ack.rs # ACK tracking, RTT (Jacobson/Karels)
├── handshake.rs # 3-phase handshake
├── mux.rs # smux v1 multiplexer (port forwarding)
├── port_forward.rs # TCP tunneling
├── rate_limit.rs # Token bucket
└── python/ # PyO3 bindings
Security
#![forbid(unsafe_code)]zeroizescrubs session tokens from memory on drop- Target format validation (EC2 instance, managed instance, ARN)
- SSRF protection (AWS endpoint validation)
- Rate limiting (configurable token bucket)
- TLS required (WSS only)
- Dead connection detection via pong tracking
- AWS transport encryption (all SSM traffic is encrypted)
See Security Documentation for threat model and details.
License
MIT License. See LICENSE.