Expand description
A Rust implementation of the AWS Systems Manager Session Manager protocol.
The official session-manager-plugin is a CLI binary. This is a library:
open sessions, stream bytes, and forward ports from inside your own async
application, with no subprocess and no plugin to install.
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?;§What you get
| Capability | Where |
|---|---|
| Shell and command sessions | Session, documents |
| TCP port forwarding (smux-multiplexed) | PortForwarder |
| End-to-end KMS session encryption | crypto (feature kms) |
| Interactive terminal | InteractiveShell (feature interactive) |
| Automatic reconnection | ReconnectingSession |
| Many concurrent sessions | SessionPool |
| Metrics hooks | metrics |
§Session lifetime
A Session is either running or closed, and every way it can end —
terminate, the agent hanging up, a dead network, a
protocol violation — resolves Session::closed and records a
CloseReason. Build on that signal rather than polling:
tokio::select! {
() = session.closed() => {
eprintln!("session ended: {}", session.close_reason().unwrap());
}
_ = do_work(&session) => {}
}§Ordering and delivery
The protocol layer handles sequencing, acknowledgement, retransmission and
reordering, so Session::send and Session::output behave like an
ordered, lossless byte stream. Message boundaries are an artefact of chunking
and carry no meaning.
§Feature flags
| Feature | Default | Effect |
|---|---|---|
interactive | yes | terminal and InteractiveShell; pulls in crossterm |
kms | yes | KMS session encryption; pulls in aws-sdk-kms and aes-gcm |
python | no | PyO3 bindings |
extension-module | no | Link the bindings as a Python extension module; set by maturin |
Without kms, a session whose account requires encrypted sessions fails the
handshake with an explicit error rather than downgrading to plaintext.
extension-module is separate from python because it leaves the CPython
symbols for the interpreter to resolve at load time: correct for a wheel,
fatal for a test binary. --all-features therefore does not link; name the
features you want.
§Not affiliated with AWS
This is an independent implementation, not endorsed by or sponsored by Amazon Web Services, Inc.
Re-exports§
pub use builder::SessionBuilder;pub use documents::SessionType;pub use documents::SsmDocument;pub use errors::Error;pub use errors::Result;pub use metrics::MetricsRecorder;pub use mux::SmuxConfig;pub use mux::SmuxSession;pub use mux::SmuxStream;pub use pool::PoolConfig;pub use pool::PoolStats;pub use pool::SessionPool;pub use port_forward::PortForwardConfig;pub use port_forward::PortForwarder;pub use reconnect::ReconnectConfig;pub use reconnect::ReconnectEvent;pub use reconnect::ReconnectingSession;pub use session::CloseReason;pub use session::DocumentSpec;pub use session::Session;pub use session::SessionConfig;pub use session::SessionManager;pub use shutdown::install_signal_handlers;pub use shutdown::ShutdownSignal;pub use interactive::InteractiveConfig;pub use interactive::InteractiveShell;pub use terminal::TerminalSize;
Modules§
- ack
- Reliable delivery: acknowledgements, retransmission and RTT estimation.
- binary_
protocol - The AWS SSM Session Manager binary wire format.
- builder
- Fluent construction of sessions.
- crypto
- KMS session encryption (AES-256-GCM).
- documents
- Typed wrappers for the AWS-managed Session Manager documents.
- errors
- Error types for
aws-ssm-bridge. - handshake
- The SSM agent handshake.
- interactive
- A complete interactive shell, terminal and all.
- metrics
- Optional metrics hooks.
- mux
- smux v1 stream multiplexing over one SSM data channel.
- pool
- Managing many concurrent sessions.
- port_
forward - Local TCP port forwarding over an SSM session.
- reconnect
- A session that rebuilds itself when the connection drops.
- session
- Session lifecycle: starting, using and ending an SSM session.
- shutdown
- Cooperative cancellation for long-running session work.
- terminal
- Terminal plumbing for interactive sessions.
Structs§
- Output
Stream - A borrowed view of the session’s output stream.
Enums§
- Endpoint
Policy - Which WebSocket endpoints the client is willing to connect to.
Constants§
- VERSION
- The version of this crate.