Skip to content

Attach a pre-populated EBS volume from a snapshot at launch (--attach-volume snap-xxx:/mount:ro) #144

Closed

Description

@scttfrdmn

Filed as the spawn-side primitive that nf-spawn#45 depends on (consumer-facing ext.volumes). nf-spawn can't implement per-process data volumes until spawn launch can attach one, so this lands first.

Request

Let spawn launch attach an additional EBS volume created from a snapshot, mounted at a given path (optionally read-only), on a stock AMI — so large reference data (the motivating case: a ~16 GB Kraken2 k2_pluspf DB for nf-core/taxprofiler) doesn't have to be baked into a custom AMI.

Proposed surface (repeatable):

spawn launch ... --attach-volume snap-0abc123:/opt/databases/kraken2:ro

Format snapshot:mountpoint[:ro]. Allow multiple. (Could also accept a bare size for a fresh blank volume later, but snapshot-backed is the use case here.)

Why not the existing storage flags

--volume-size is root-only. --efs-id / --fsx-id / --fsx-create exist but are a different access model (shared network filesystem, separate lifecycle). For a read-only reference blob that wants to be local block storage and created-once-from-snapshot, an attached EBS volume is the right primitive — and it's the one piece spawn is missing.

Where it plugs in (confirmed in the code)

  1. Flag + config — cmd/launch.go (~line 216, by --volume-size); add to LaunchConfig in pkg/aws/client.go:102 (e.g. AttachVolumes []AttachVolumeSpec{SnapshotID, MountPoint, ReadOnly}).
  2. Block-device mapping — pkg/aws/client.go:buildBlockDevices (~line 658) currently emits only the root /dev/xvda. Append one BDM per attach spec: DeviceName (e.g. /dev/sdf, /dev/sdg, …), Ebs{SnapshotId, DeleteOnTermination:true, VolumeType:gp3}. Note the Nitro wrinkle: on Nitro instances the requested /dev/sdf shows up as an NVMe device (/dev/nvme1n1…) with a non-deterministic order — the mount step must resolve the real device (by volume-id via nvme id-ctrl/lsblk, or by the EBS volume tag), not assume /dev/sdf.
  3. Mount in user-data — pkg/userdata/storage.go already has FSx/EFS mount templates and a StorageConfig; add an attached-EBS branch: resolve the NVMe device for each snapshot's volume, mkdir -p <mount>, mount -o ro,noatime (or rw) <dev> <mount>, append to /etc/fstab with _netdev-equivalent ordering, and (if rw blank) mkfs — but for snapshot-backed RO, never mkfs.
  4. Tags — write spawn:attached-volume-* tags via buildTags so the reaper/inventory see them (and so the auto-created volumes are cleaned with the instance — DeleteOnTermination:true already covers the EBS lifecycle).

Cost / lifecycle notes

  • The attached volume is created from the snapshot at launch and should set DeleteOnTermination: true so it dies with the ephemeral instance (the lifecycle invariant — "everything dies eventually"). The snapshot persists and is reused; each task gets a fresh cheap copy.
  • A read-only reference volume mounted by many concurrent task instances = many EBS volumes from one snapshot; that's expected and is the cost the user is explicitly trading against per-task S3 download / oversized root volumes.

Validation

  • Unit: flag parsing (snap:mount:ro → spec; multiple; bad forms rejected), buildBlockDevices appends the snapshot BDMs with distinct device names, storage user-data emits the RO mount + NVMe device resolution + no mkfs for snapshot-backed.
  • Live (paid, TTL + terminate + leak-check per the cost rule): launch a stock AL2023 arm64 instance with --attach-volume <kraken2-snap>:/opt/databases/kraken2:ro, confirm the DB is present and read-only at the mount, terminate, and verify the auto-created data volume is gone (DeleteOnTermination) — no leaked volumes or snapshots.

Cross-refs

  • Consumer/feature request: nf-spawn#45 (ext.volumes per process → forwards to this flag).
  • Tradeoff analysis the filer wrote lives in the aws-microbiome-demo repo at docs/ami-vs-data-volume.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions