Skip to content

feat: spawn snapshot create — build EBS snapshot via EBS direct APIs (#147 Part A) - #148

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/147-snapshot-create-ebs-direct
Jun 13, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/147-snapshot-create-ebs-direct

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Part A of #147 (per the agreed scope: ship the instance-free snapshot builder now; plan Part B/FSR separately). The build side that pairs with --attach-volume (#144, shipped in v0.46.0).

What

spawn snapshot create --from <raw-image> --size <GiB> populates a new EBS snapshot directly from a raw disk/filesystem image using the EBS direct APIs — no EC2 instance, no attached volume. Source is a local path or s3://bucket/key.

spawn snapshot create --from ./kraken2.raw --size 20 --name kraken2-k2pluspf
spawn snapshot create --from s3://my-bucket/kraken2.raw --size 20 --region us-east-1
# then:
spawn launch run1 --attach-volume snap-0abc:/opt/databases/kraken2:ro

This drops the launch→download→extract→ami create→terminate bake dance from the data path.

How

  • pkg/aws/snapshot_build.go
    • planSnapshotBlocks — the pure, fully-tested core: split the image into fixed 512 KiB blocks (the only size the API accepts), skip all-zero blocks (sparse — a snapshot reads unwritten blocks as zero), zero-pad the final short block, compute each block's base64 SHA256 (the PutSnapshotBlock checksum) and the linear-aggregation checksum (CompleteSnapshot = base64 SHA256 over the concatenated raw per-block digests in index order).
    • BuildSnapshotFromReader — StartSnapshot → PutSnapshotBlock×N → CompleteSnapshot, then the EC2 SnapshotCompleted waiter so the snapshot is immediately attachable. Fits-check against --size; encryption/KMS supported.
    • OpenImageSource — streams the image from a local file or S3 object.
  • cmd/snapshot.go — spawn snapshot create (text/json), --from/--size required, --name/--description/--region/--encrypted/--kms-key.

Important scoping: raw image, not an archive

--from is read verbatim as the block device — it must be a raw filesystem image, not a .tar.gz. The help text says so explicitly and points at building one (truncate + mkfs.ext4 -d). Doing that conversion for the user (a directory/tarball → filesystem image) needs a Linux fs-builder and is Part B — it can't run portably on the macOS host this CLI targets. I'd rather ship the unambiguous primitive than guess a fs layout.

Tests

Pure block/checksum logic is unit-tested (short block + padding, sparse-zero skip with preserved indices, all-zero → no blocks, exact multiples, deterministic + independently-recomputed aggregation checksum, parseS3URI, tags). The EBS direct endpoint isn't modeled by substrate, so the live upload is deferred to a paid validation (below). make check green.

Follow-ups (will comment on #147)

  • Part B — FSR: enable Fast Snapshot Restore on --attach-volume/at launch so a wide fan-out doesn't each eat first-touch lazy-load latency. This bills per-AZ-hour while enabled, so it needs an explicit opt-in + auto-disable-on-drain design before implementing — deliberately not in this PR.
  • Part B — fs-builder: --from <dir>/tarball → build a filesystem image (Linux-only path).
  • Live validation: build a real snapshot from an S3 raw image, --attach-volume it, confirm contents + checksum; clean up. Pairs with Attach a pre-populated EBS volume from a snapshot at launch (--attach-volume snap-xxx:/mount:ro) #144's live test.

…147 Part A)

Adds `spawn snapshot create --from <raw-image> --size <GiB>` to populate a new
EBS snapshot directly from a raw disk/filesystem image using the EBS direct
APIs (StartSnapshot → PutSnapshotBlock → CompleteSnapshot) — no EC2 instance,
no attached volume. The source is a local path or s3://bucket/key.

This is the instance-free build side of #147; it pairs with the --attach-volume
read side (#144) so large reference data lives in a re-snapshottable volume
instead of a baked AMI.

- pkg/aws/snapshot_build.go: planSnapshotBlocks (pure: 512 KiB block split,
  sparse all-zero skip, final-block zero-pad, per-block base64-SHA256 checksum
  + linear-aggregation checksum), BuildSnapshotFromReader (the direct-API flow
  + EC2 SnapshotCompleted waiter), OpenImageSource (local/s3 streaming).
- cmd/snapshot.go: the snapshot/create command (text/json output), with --from
  documented as a RAW image (not an archive — the fs-builder is Part B).
- Pure block/checksum logic is unit-tested (substrate doesn't model the EBS
  direct endpoint); the live upload is deferred to a paid validation.

Part B (FSR warming on attach + a directory/tarball→filesystem-image builder)
to be planned on the issue.
@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 27.70563% with 167 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/snapshot_build.go 31.61% 105 Missing and 1 partial ⚠️
cmd/snapshot.go 19.73% 61 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 39d39c1 into main Jun 13, 2026
2 of 3 checks passed
@scttfrdmn
scttfrdmn deleted the feat/147-snapshot-create-ebs-direct branch June 13, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant