Repository navigation
Description
Four things about spawn launch --command that each cost a run to discover. They are related in that none of them is visible from the launch output — the instance simply idles to TTL while spawn reports success.
1. It prints success, then the command fails silently
▶️ Executing --command
✅ Command execution started (logs: /var/log/spawn-command.log)
...
fatal error: An error occurred (403) when calling the HeadObject operation: Forbidden
The 403 is the --command itself failing on its first line. Nothing surfaces it: spawn launch had already reported ✅, and the instance then sat idle for 38 minutes until I went looking. /var/log/spawn-command.log existed but was empty; the error was only in /var/log/cloud-init-output.log.
Suggested: if --command exits non-zero, say so — and ideally honour --on-complete terminate for a failed command rather than idling to TTL. A command that dies in its first second should not bill an hour.
2. A launch instance's role cannot read the account's own S3 bucket
The 403 above was aws s3 cp s3://<my-own-bucket>/scripts/x.sh — same account, same region. A spawn task run in the same account stages inputs from that bucket without any extra flags, so the asymmetry is surprising: the task path can read my bucket, the launch path cannot. This looks like the same family as #579 (launch-instance role returning 403 on s3:ListBucket).
Workaround that fixed it: --iam-managed-policies arn:aws:iam::aws:policy/AmazonS3FullAccess. That works, but it is far broader than "read the bucket you already own," and it is not discoverable from the failure.
Suggested: give the launch role the same bucket access the task path has, or fail the launch early with a clear message naming the missing permission.
3. No docker, no fuse
A task run instance has Docker (it is how the task's container runs). A launch instance does not:
command -v docker -> NO_DOCKER
command -v fusermount3 -> NO_FUSERMOUNT
That is defensible — different purpose — but it is undocumented in the flag help, and for anyone using --command to run a pinned container (the obvious reason to reach for launch when task run cannot express something) it is a surprise. sudo dnf install -y docker fuse fuse3 && sudo systemctl enable --now docker fixes it in ~20 s.
Suggested: one line in --command's help — "runs on the bare instance; Docker is not installed" — would be enough.
4. --command runs as a non-root user
whoami → scttfrdmn. So a script that does mkdir -p /opt/work, mv something /usr/local/bin, or dnf install fails without stopping the script, and the failures look like unrelated downstream errors. In my case a downloaded binary landed at /tmp/lith correctly but the mv to /usr/local/bin failed, so the next line reported lith: command not found — which reads as a download problem and is not.
Suggested: document it. "Runs as the login user; use sudo for privileged steps" in the help for --command would have saved two launches.
Impact
Three launches and roughly $1 of idle instance time to get a --command script running, none of it visible without SSM-ing in and reading cloud-init-output.log. Items 1 and 2 are the substantive ones; 3 and 4 are documentation.
Context: measuring copy-vs-mount data paths (aws s3 cp vs FSx Lustre vs EFS vs lith) for the scientific-codes-cookbook, where --instance-type pinning made launch the right tool (see #610). spawn 0.111.1, us-west-2, AL2023 arm64.
Activity
fix(launch): report --command's outcome, signal completion, and let i…
scttfrdmn commentedon Oct 2, 2026
Fixed in #630 (merged as `ab7ed32`), and validated on real hardware — details below, because one of your four items turned out to be worse than reported and another couldn't be fixed as suggested.
1. The success message — and something you didn't see
You were right that the exit code was discarded. Two notes:
`$?` would not have been enough. After `cmd | tee log`, `$?` is tee's status — `0` even when the command failed, so the naive fix would have kept reporting every failure as success. Verified under bash: `$?`=0 while `${PIPESTATUS[0]}`=7. The code now comes from `PIPESTATUS[0]`, lands in `/tmp/SPAWN_EXITCODE`, and the pass/fail line prints when it's actually known.
The bigger finding: `--on-complete` had never fired on this path at all. The bootstrap never wrote `/tmp/SPAWN_COMPLETE` — only `spawn task run` did — so nothing ever signalled completion and the instance ran to its full TTL whether the command passed or failed. Your 38 idle minutes weren't a quirk of the failure; `--on-complete terminate` has simply never worked with `--command`. That's what made this worth more than a message fix.
Measured on a real t3.micro, `--command 'exit 7' --on-complete terminate --ttl 15m`:
A separate instance confirmed the files: `EXITCODE=7`, `{"status": "failed", "exit_code": 7, "source": "command"}`.
Heads-up, since it's a behaviour change: instances that used to sit until TTL now take their `--on-complete` action when the command exits, pass or fail. If you want a failed box kept for inspection, use `--on-complete stop` or omit the flag.
2. The S3 403 — your suggested fix wasn't implementable, so here's the equivalent
"Give the launch role the same bucket access the task path has" can't be done directly: `spawn task run` derives its policy from the spec's declared inputs and outputs, and a `--command` is an opaque shell string with nothing to derive from.
So `spawn launch` now has the same declarative capability, using the same policy builder:
```sh
spawn launch job --command '...' --s3-read my-inputs --s3-write my-results
```
which grants `s3:GetObject`+`ListBucket` on `my-inputs` and `s3:PutObject` on `my-results` — and nothing else. That's the least-privilege answer to the `AmazonS3FullAccess` workaround you found; note `--iam-policy s3:ReadOnly` was also broader than it looks (`Resource: "*"` — every bucket in the account). Wildcards, ARNs and `s3://` URIs are refused, since the name goes straight into a Resource ARN.
3 & 4. Both now in `--command`'s help
That it runs on the bare instance as the login user, not root (use `sudo`), and that Docker and fuse are not installed, unlike a `spawn task run` instance.
On your `mv` observation: the generated script does set `-e`, and I confirmed a failing command aborts it (`false; echo unreachable` → exit 1, the echo never runs). If you still see a script continuing past a failure, that's worth its own issue with the exact command — `set -e` has real exemptions (a failure inside `&&`/`||`, a subshell whose status is tested) and it'd be useful to know which one bit you.
One thing deliberately not changed
The command stays backgrounded. spored is installed and started later in the bootstrap, so waiting for the command would block cloud-init and leave TTL, idle and cost enforcement unarmed for its whole duration — a worse and quieter failure than this one. The exit code is captured in a backgrounded subshell instead, with a test that fails if anyone removes the `&`.
Thanks for the four-part report — the `whoami`, the empty log, and the cloud-init-vs-command-log distinction are what made this quick to pin down.
chore(release): v0.113.0
fix(sweep): honour --s3-read/--s3-write, via one IAM predicate shared…
fix(sweep): honour --s3-read/--s3-write, via one IAM predicate shared…