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 aws_ssm_bridge::SessionBuilder;
use futures_util::StreamExt;
let session = SessionBuilder::new("i-0123456789abcdef0").start().await?;
session.wait_ready().await?;
let mut output = session.output();
session.send(&b"uname -a\r"[..]).await?;
while let Some(chunk) = output.next().await {
print!("{}", String::from_utf8_lossy(&chunk));
}
session.terminate().await?;
Install
cargo add aws-ssm-bridge
cargo add tokio --features rt-multi-thread,macros
pip install aws-ssm-bridge
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 aws_ssm_bridge::SessionBuilder;
use futures_util::StreamExt;
let session = SessionBuilder::new("i-0123456789abcdef0")
.region("eu-central-1")
.reason("incident 4711") // recorded in CloudTrail
.start()
.await?;
let mut output = session.output(); // subscribe *before* sending
session.wait_ready().await?;
session.send(&b"df -h\r"[..]).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 std::sync::Arc;
use aws_ssm_bridge::{
documents::PortForwardingToRemoteHost, install_signal_handlers,
PortForwardConfig, PortForwarder, SessionBuilder, ShutdownSignal,
};
let shutdown = ShutdownSignal::new();
install_signal_handlers(shutdown.clone());
let session = Arc::new(
SessionBuilder::new("i-0123456789abcdef0")
.document(PortForwardingToRemoteHost::new("db.internal", 5432))
.start()
.await?,
);
let forwarder = PortForwarder::bind(PortForwardConfig {
local_addr: "127.0.0.1:15432".parse()?,
..Default::default()
})
.await?;
println!("psql -h 127.0.0.1 -p {}", forwarder.local_addr().port());
forwarder.forward(session, shutdown).await?;
Each accepted connection becomes its own smux stream inside one WebSocket, so concurrent connections neither block nor corrupt each other.
Typed documents
use aws_ssm_bridge::documents::*;
PortForwardingSession::new(3306) // port on the instance
PortForwardingToRemoteHost::new("db.internal", 5432) // through the instance
SshSession::new() // ssh ProxyCommand transport
InteractiveCommand::new("top") // with a pty
NonInteractiveCommand::new("systemctl status nginx") // without a pty
Python
import asyncio
from aws_ssm_bridge import SessionManager
async def main():
manager = await SessionManager.new(region="eu-central-1")
async with await manager.start_session("i-0123456789abcdef0") as session:
await session.send(b"uname -a\r")
async for chunk in session.output():
print(chunk.decode(errors="replace"), end="")
asyncio.run(main())
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.
tokio::select! {
() = session.closed() => eprintln!("gone: {}", session.close_reason().unwrap()),
result = do_work(&session) => result?,
}
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
just # list every recipe
just check # what CI runs: fmt, clippy, tests, docs
just matrix # every feature combination
just bench # framing and reliability micro-benchmarks
just fuzz # cargo-fuzz over the network-facing parsers
just python # build and install the wheel
just site # serve the documentation site locally
just release-check # everything above, plus MSRV, --locked, publish dry run
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 aws_ssm_bridge-0.5.0.tar.gz.
File metadata
- Download URL: aws_ssm_bridge-0.5.0.tar.gz
- Upload date:
- Size: 325.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e67b660bc82d9fbb86cf62197df5ed95d52dfb0db020f1acb8d0be32bd88d9d4
|
|
| MD5 |
75b036c5896414e065bfde9e4a90e201
|
|
| BLAKE2b-256 |
34159211ff66a072447ae71fda8081dcf001e60f1d8cbe7687eb4ed2849b6497
|
Provenance
The following attestation bundles were made for aws_ssm_bridge-0.5.0.tar.gz:
Publisher:
release.yml on hupe1980/aws-ssm-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aws_ssm_bridge-0.5.0.tar.gz -
Subject digest:
e67b660bc82d9fbb86cf62197df5ed95d52dfb0db020f1acb8d0be32bd88d9d4 - Sigstore transparency entry: 2469842520
- Sigstore integration time:
-
Permalink:
hupe1980/aws-ssm-bridge@cd4f7c3586d40352b28507d913af30edb43ddfdd -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/hupe1980
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cd4f7c3586d40352b28507d913af30edb43ddfdd -
Trigger Event:
push
-
Statement type:
File details
Details for the file aws_ssm_bridge-0.5.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: aws_ssm_bridge-0.5.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 5.2 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57ca53551d2f977e9a18d1d9115b7d47e956b975bb17329e36a5de355bbea8c4
|
|
| MD5 |
75e7161f659917616876380908f3dd6e
|
|
| BLAKE2b-256 |
25cdabe278bf6f62a8c5ea77d1aea12488b659828e0be8734a4ce139412f58ee
|
Provenance
The following attestation bundles were made for aws_ssm_bridge-0.5.0-cp38-abi3-win_amd64.whl:
Publisher:
release.yml on hupe1980/aws-ssm-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aws_ssm_bridge-0.5.0-cp38-abi3-win_amd64.whl -
Subject digest:
57ca53551d2f977e9a18d1d9115b7d47e956b975bb17329e36a5de355bbea8c4 - Sigstore transparency entry: 2469842539
- Sigstore integration time:
-
Permalink:
hupe1980/aws-ssm-bridge@cd4f7c3586d40352b28507d913af30edb43ddfdd -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/hupe1980
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cd4f7c3586d40352b28507d913af30edb43ddfdd -
Trigger Event:
push
-
Statement type:
File details
Details for the file aws_ssm_bridge-0.5.0-cp38-abi3-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: aws_ssm_bridge-0.5.0-cp38-abi3-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 7.7 MB
- Tags: CPython 3.8+, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d9df380ab35b24f67a0e233208221b8bf8f16456e63c17142586f3557e1fc88
|
|
| MD5 |
05cba04c95b637cbe939cbdad3c8d15b
|
|
| BLAKE2b-256 |
86fa1f0af481da72edd1c204ee9e9cb76c76305b1604867ed5bdb348e125ef09
|
Provenance
The following attestation bundles were made for aws_ssm_bridge-0.5.0-cp38-abi3-manylinux_2_39_x86_64.whl:
Publisher:
release.yml on hupe1980/aws-ssm-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aws_ssm_bridge-0.5.0-cp38-abi3-manylinux_2_39_x86_64.whl -
Subject digest:
4d9df380ab35b24f67a0e233208221b8bf8f16456e63c17142586f3557e1fc88 - Sigstore transparency entry: 2469842594
- Sigstore integration time:
-
Permalink:
hupe1980/aws-ssm-bridge@cd4f7c3586d40352b28507d913af30edb43ddfdd -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/hupe1980
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cd4f7c3586d40352b28507d913af30edb43ddfdd -
Trigger Event:
push
-
Statement type:
File details
Details for the file aws_ssm_bridge-0.5.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: aws_ssm_bridge-0.5.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.0 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66c0fbada112964521bd329914fdae27591e39b5d4ecbefe8ba7a2fc36928308
|
|
| MD5 |
dc9a8a87122d4aae3d1899fa9253907e
|
|
| BLAKE2b-256 |
90ea766e4c6212fb2301084c6aaab09439f1e8555f3cde21729b512bc28b68b8
|
Provenance
The following attestation bundles were made for aws_ssm_bridge-0.5.0-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on hupe1980/aws-ssm-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aws_ssm_bridge-0.5.0-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
66c0fbada112964521bd329914fdae27591e39b5d4ecbefe8ba7a2fc36928308 - Sigstore transparency entry: 2469842568
- Sigstore integration time:
-
Permalink:
hupe1980/aws-ssm-bridge@cd4f7c3586d40352b28507d913af30edb43ddfdd -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/hupe1980
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cd4f7c3586d40352b28507d913af30edb43ddfdd -
Trigger Event:
push
-
Statement type: