aws-ssm-bridge
A Rust implementation of the AWS Systems Manager Session Manager protocol, with async Python bindings.
Not affiliated with AWS. This is an independent implementation of a documented-by-observation protocol, not endorsed or sponsored by Amazon Web Services, Inc.
What this is for
The official session-manager-plugin is a CLI binary: you shell out to
it, hand it JSON on argv, and parse whatever it prints. That is fine for a
terminal and awkward for everything else.
aws-ssm-bridge is a library. Open sessions, stream bytes and forward ports
from inside your own async application — no subprocess, no plugin to install, no
output scraping.
use SessionBuilder;
use StreamExt;
let session = new.start.await?;
session.wait_ready.await?;
let mut output = session.output;
session.send.await?;
while let Some = output.next.await
session.terminate.await?;
Install
Requires the same IAM permissions as the official plugin: ssm:StartSession on
the target, and ssm:TerminateSession on your own sessions.
Capabilities
| Shell and command sessions | Interactive shells, AWS-StartInteractiveCommand, AWS-StartNonInteractiveCommand |
| Port forwarding | smux-multiplexed, many concurrent TCP connections over one session |
| KMS session encryption | AES-256-GCM end-to-end, for accounts that mandate encrypted sessions |
| Interactive terminal | Raw byte passthrough, SIGWINCH resize, panic-safe restore |
| Reconnection | Durable output stream across reconnects, full-jitter backoff |
| Pooling | Bounded concurrent sessions with automatic reaping |
| Observability | tracing spans throughout, pluggable metrics recorder |
| Python | Full async API, type stubs, context managers |
Verified against a live SSM agent (3.3.3572.0): shell sessions, handshake, six concurrent multiplexed TCP streams, and clean teardown.
Guided tour
Shell session
use SessionBuilder;
use StreamExt;
let session = new
.region
.reason // recorded in CloudTrail
.start
.await?;
let mut output = session.output; // subscribe *before* sending
session.wait_ready.await?;
session.send.await?;
Send \r, not \n: a remote pty maps carriage return to newline, but Windows
shells behind winpty do not accept a bare line feed.
Port forwarding
use Arc;
use ;
let shutdown = new;
install_signal_handlers;
let session = new;
let forwarder = bind
.await?;
println!;
forwarder.forward.await?;
Each accepted connection becomes its own smux stream inside one WebSocket, so concurrent connections neither block nor corrupt each other.
Typed documents
use *;
new // port on the instance
new // through the instance
new // ssh ProxyCommand transport
new // with a pty
new // without a pty
Python
= await
await
Session lifetime
A session is either running or closed. Every way it can end — a clean
terminate(), the agent hanging up, a dead network, a protocol violation —
resolves Session::closed() and records a CloseReason.
select!
That one guarantee is what makes the layers above it work: the port forwarder
stops accepting when the tunnel dies, the pool reaps dead entries, and
ReconnectingSession knows when to rebuild. There is no state in which the
handle looks alive but nothing is running.
Reconnection restores connectivity, not continuity — a new session is a new process on the target, so shell state and anything printed while disconnected are gone.
Feature flags
| Feature | Default | Effect |
|---|---|---|
interactive |
✅ | terminal and InteractiveShell; pulls in crossterm |
kms |
✅ | KMS session encryption; pulls in aws-sdk-kms and aes-gcm |
python |
— | PyO3 bindings |
extension-module |
— | Link the bindings as a Python extension module; set by maturin when building a wheel |
Built without kms, a session whose account mandates encryption fails the
handshake with an explicit error instead of quietly running in plaintext.
extension-module is deliberately separate from python: it leaves the CPython
symbols for the interpreter to resolve at load time, which is right for a wheel
and fatal for a test binary. Because --all-features would enable it, name the
features you want instead — --features interactive,kms is what CI runs.
Examples
| Rust | |
|---|---|
cargo run --example shell -- i-… "uname -a" |
Run a command, print the output |
cargo run --example interactive -- i-… |
Full interactive shell |
cargo run --example port_forward -- i-… 5432 127.0.0.1:15432 |
TCP tunnel |
cargo run --example reconnecting -- i-… |
Survive a dropped connection |
cargo run --example fleet -- "uptime" i-… i-… |
One command, many instances |
cargo run --example metrics -- i-… |
Wire up the metrics hooks |
Python equivalents live in python_examples/.
Documentation
Full documentation: hupe1980.github.io/aws-ssm-bridge
| Getting started | Credentials, your first session, port forwarding, every CloseReason |
| Architecture | How it is layered, and why the non-obvious parts are that way |
| Wire protocol | The binary format, reliability, smux, KMS encryption |
| Security | Threat model, and what is explicitly not defended against |
| Python API | The full async binding surface |
| API reference | Every type and method, on docs.rs |
| Changelog | What changed, and how to migrate |
The site is built with Zola from site/;
just site serves it locally.
Security
unsafe_code = "forbid"for the whole crate, so anyunsafefails the build.- The session token travels only in the data-channel open message — never in a URL, where proxies and traces would record it.
- SHA-256 payload digests are verified, matching the reference implementation; a mismatch ends the session rather than delivering corrupt bytes.
- The data channel refuses any endpoint that is not an AWS SSM messages host.
- KMS session encryption is AES-256-GCM with a per-message nonce, and a client that cannot negotiate it fails the handshake rather than downgrading.
See the security model for the threat model and what is explicitly not defended against.
Development
The MSRV is set by the AWS SDK, not by this crate's own code. just msrv
verifies it against the committed lockfile — which is the only way the check
means anything, since an unlocked resolve pulls in dependencies that need a
newer toolchain than users actually get.
License
MIT. See LICENSE.