Relay scp downloads through S3 to bypass the SSM throughput ceiling - #44
Open
joehoyle wants to merge 1 commit into
Open
Relay scp downloads through S3 to bypass the SSM throughput ceiling#44joehoyle wants to merge 1 commit into
joehoyle wants to merge 1 commit into
Conversation
The SSM agent paces shell output at ~1KB per millisecond (a hardcoded 1024-byte payload + time.Sleep(time.Millisecond) in its writePump), which caps downloads streamed over the session at ~1-2MB/s regardless of bandwidth. Instead, have the remote copy the file to the stack's uploads bucket (--acl private, as the bucket is public by default), presign a short-lived URL, and download it over plain HTTPS. The SSM session is only used as the control channel, with sentinel-delimited exec to run commands and capture output/exit codes reliably through the PTY echo. Falls back to the existing base64-over-PTY transfer when the aws cli or S3_UPLOADS_BUCKET isn't available on the remote. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Downloading files with
altis-cli stack scptops out at ~1.3MB/s of file data no matter how fast the connection is. The bottleneck is the SSM agent itself: its shell output pump reads at most 1024 bytes from the PTY and thentime.Sleep(time.Millisecond)on every iteration (shell.gowritePump,StreamDataPayloadSize = 1024), a hard ~1-2MB/s per-session ceiling. It's compiled in — no agent config, session document parameter, or client-side change can lift it, and the port-forwarding plugins have the identical loop. Base64 framing eats a further 25% of that, so a 1GB database dump takes around 13 minutes. This is a well-known SSM limitation (aws/amazon-ssm-agent#227).Proposed solution
Stop sending the bulk bytes through the session at all. The remote already has the aws cli and credentials for the stack's uploads bucket, so for downloads the CLI now:
s3://$S3_UPLOADS_BUCKET/tmp/altis-cli/<random>/<name>— with--acl private, since the uploads bucket is publicly readable by default.finally).The SSM session becomes a control channel only. Commands run through a new
exec()helper that brackets output in unique sentinel tokens so output and exit codes can be captured reliably; the tokens are written with adjacent-quote splitting ("__ALTIS_""x_B__") so the PTY echoing the typed command back can never false-match them. Theaws s3 cpprogress line is parsed from the PTY echo and rendered in the existing progress bar UI, so both legs (remote→S3, S3→local) report live progress and speed.Trade-offs and alternatives considered:
stty -echo) only helps uploads — downloads are pinned at the agent's output ceiling, which we can't change. Uploads are unchanged here and still use the old path (presigning a PUT needs the SDK; the aws cli can only presign GETs).S3_UPLOADS_BUCKET), the command falls back to the existing base64-over-PTY transfer automatically, with the reason shown under-v— so no environment gets worse, slow is the floor.Notes for reviewers / ops:
--acl privaterequiress3:PutObjectAclon the instance role; without it the cp fails and the CLI silently falls back to the slow path.tmp/altis-cli/. A lifecycle rule on that prefix would be the proper backstop; deliberately not handled CLI-side.🤖 Generated with Claude Code