Skip to content

fix(ec2): a launch materializes the volumes its block device mappings describe (#666) - #668

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/666-launch-block-device-mappings
Aug 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/666-launch-block-device-mappings

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

RunInstances accepted BlockDeviceMapping.N.* and parsed none of it.
runInstancesWithTags read thirteen parameter groups and no block device mapping was
among them, so a request naming a 60 GiB /dev/xvda root volume succeeded and
DescribeVolumes reported nothing for the instance — substrate silently accepting a
parameter it did not model, the shape #97 exists to remove.

The value was not merely hidden, it was unreachable. AWS's
EbsInstanceBlockDevice — the shape an instance renders per device — carries
volumeId, attachTime, deleteOnTermination and status, but no size. So
DescribeVolumes is the only API surface on which a launch-specified size can be
observed at all, which is why exposing blockDeviceMapping on DescribeInstances
would not have closed this.

What changed

A launch now materializes real EC2Volume records in the same volume: namespace
CreateVolume writes to, each attached to the new instance, so DescribeVolumes is
the single source of truth for provisioned and launch-created volumes alike — how
real EC2 unifies the two.

  • emulator/ec2_block_devices.go (new) — the parser and the materializer.
    ec2ParseBlockDeviceMappings(params, prefix) follows ec2ParseNetworkInterfaces'
    idiom exactly: 1-indexed, contiguous, terminating on a present bool that ORs
    every member, with the prefix argument that lets one parser serve RunInstances
    ("") and CreateLaunchTemplate ("LaunchTemplateData.").
  • Termination is honored. TerminateInstances deletes a volume whose attachment
    deletes on termination and makes one that does not available with no attachment.
    This half is what made the parsing safe to land: without it a volume would report
    deleteOnTermination=true while sitting in-use on a terminated instance forever
    — a state real EC2 never reaches, a new inaccuracy in place of the old silence.
  • iops and throughput reach the wire. EC2Volume already stored IOPS and
    never rendered it; Throughput had nowhere to be stored.
  • DescribeVolumes gained six filters — attachment.device,
    attachment.delete-on-termination, volume-type, size, availability-zone,
    snapshot-id — beside the three it had. Each is one the reference documents, and
    each is a question the new state makes answerable.
  • AttachVolume sets and renders deleteOnTermination: false explicitly.
  • A fleet reaches mappings through its launch template, which now carries them;
    ec2_fleet.go needed no change because CreateFleet forwards the template
    reference rather than the caller's own parameters.

The two decisions, and the evidence

Every launch produces at least one volume. A real instance always has a root
volume whether or not the request mentions one, and DescribeImages already reported
an 8 GiB /dev/sda1 mapping for every AMI substrate serves, so producing none left
the two disagreeing about the same instance. Root devices are recognized by name:
/dev/sda1 and /dev/xvda, the two spellings AWS's device-naming reference gives
for the HVM root ("Differs by AMI"). Recognizing only /dev/sda1 would have answered
this issue's own /dev/xvda repro with two volumes — a 60 GiB one plus a spurious
8 GiB root.

DeleteOnTermination defaults to true for data volumes too. Counter-intuitive,
and AWS's documented behaviour: the preserving-volumes-on-termination table splits
on how the volume was attached, not on what it is — a data volume attached at
launch through the console preserves, but through the CLI it is deleted, and
an API emulator is the CLI path. AttachVolume keeps the other default, false.

Two things AWS does not settle, recorded rather than papered over: EbsBlockDevice
documents no VolumeType default (substrate uses gp2, matching CreateVolume, so
there is one default in one place — real AMIs specify gp3 in a mapping substrate's
AMIs do not carry); and EC2Image stores no per-AMI root device, so an AMI whose
real root device is neither documented spelling is out of reach, which docs/services.md
now says.

Deliberately out of scope

blockDeviceMapping on DescribeInstances / DescribeInstanceAttribute (the shape
carries no size, so it would not answer the question this does); Ebs.KmsKeyId (left
out rather than stored and hidden); volume tag specifications, which are a
CreateVolume parity gap; and InvalidBlockDeviceMapping validation, which needed
this state to exist first. Follow-ups filed against v0.104.0.

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... (0 issues),
make test (race), make coverage (82.1% total, emulator 82.7%),
make docs-reference-check docs-versions, npm --prefix docs run build,
go vet -C test/e2e ./... && go test -C test/e2e ./... — all green.

New tests. emulator/ec2_block_devices_test.go covers the parser and materializer
in isolation (25 cases). emulator/ec2_block_devices_http_test.go covers nine
scenarios through HTTP, unmarshalling the response into a struct rather than searching
the body for vol- — the existing volume tests' strings.Index idiom cannot tell two
volumes apart, and a launch now routinely produces two. test/e2e/journey_ec2_block_devices_test.go
is the tier this was reported from, and test/e2e had no EBS coverage at all; it goes
through the real SDK, because BlockDeviceMappings is a structured input the SDK
serializes itself, so a hand-built form body proves only that substrate parses the
spelling the test's author chose.

Mutation pass, nine targets, full-package go test -race per mutant with a
gofmt/go vet gate: 8 CAUGHT, 1 EQUIVALENT, 0 survivors that matter.

Mutant Verdict
ec2LaunchVolumesFor returns nil (the bug itself) CAUGHT (6 tests)
the implicit root volume is dropped CAUGHT (6 tests)
DeleteOnTermination defaults to false CAUGHT (6 tests)
the root-device check tests only /dev/sda1 CAUGHT (6 tests)
the volume's AZ comes from region+"a" CAUGHT
terminateInstances deletes every attached volume regardless of the flag CAUGHT (2 tests)
the parser stops at index 1 CAUGHT (6 tests)
"pricing" maps to errProtoQueryXML (#653's guard) CAUGHT (6 tests)
the volume_ids index is not cleaned on termination EQUIVALENT

The EQUIVALENT one, disclosed rather than glossed: volume_ids is a write-only
index. createVolume and the new launch path append to it and deleteVolume removes
from it, but nothing reads it — describeVolumes lists the volume: key prefix
directly. So no API observation can distinguish the mutant, and no test can catch it
without asserting on state rather than behaviour. The removal call stays because
deleteVolume makes it, and a stale entry would become wrong the moment something
does read it. (A test comment claiming the index was what the assertion proved has
been corrected to say what it actually proves: the record left the namespace
DescribeVolumes lists.)

Live run through the AWS CLI on :4678, the issue's repro verbatim:

$ aws ec2 run-instances --image-id ami-0abcdef1234567890 --instance-type t3.micro \
    --block-device-mappings '[{"DeviceName":"/dev/xvda","Ebs":{"VolumeSize":60}}]'
$ aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=i-b54e18579dcf3cc8
    "VolumeType": "gp2", "Size": 60, "State": "in-use",
    "Attachments": [{"DeleteOnTermination": true, "Device": "/dev/xvda", "State": "attached"}]
$ aws ec2 terminate-instances --instance-ids i-b54e18579dcf3cc8   # terminated
$ aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=i-b54e18579dcf3cc8
    {"Volumes": []}

And the data-volume path, showing the synthesized root beside it and the performance
members on the wire:

+-----------+--------+-------+-------+--------+--------+
|    Dev    |  DoT   | Iops  | Size  | Tput   | Type   |
+-----------+--------+-------+-------+--------+--------+
|  /dev/sdf |  False |  4000 |  100  |  250   |  gp3   |
|  /dev/sda1|  True  |  None |  8    |  None  |  gp2   |
+-----------+--------+-------+-------+--------+--------+

after terminate, the preserved one alone: vol-45f7b9d0… 100 available 0 attachments.

Compatibility

DescribeVolumes now returns volumes for launched instances. A fixture that
listed all volumes and expected only what it created with CreateVolume will see a
root volume per instance — filter by volume-id or attachment.instance-id for the
old answer. TerminateInstances now deletes those volumes; a fixture that terminated
an instance and then read a volume attached at launch will find it gone unless it set
DeleteOnTermination: false. A volume attached after launch is untouched by
termination, per AWS.

Closes #666

… describe (#666)

RunInstances read thirteen parameter groups and none of them was a block device
mapping, so BlockDeviceMapping.1.Ebs.VolumeSize=60 was accepted and discarded and
DescribeVolumes reported nothing for the instance.

The value was not merely hidden, it was unreachable: AWS's EbsInstanceBlockDevice
carries no size member, so DescribeVolumes is the only API surface on which a
launch-specified size is observable. A launch now writes real EC2Volume records to
the same store CreateVolume writes to, attached to the new instance.

TerminateInstances settles them, which is what made the parsing safe to land —
otherwise a volume would report deleteOnTermination=true while sitting in-use on a
terminated instance forever.

Closes #666
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.93103% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_block_devices.go 86.57% 10 Missing and 10 partials ⚠️
emulator/ec2_plugin.go 90.36% 5 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit da5b8d4 into main Aug 20, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/666-launch-block-device-mappings branch August 20, 2026 07:32
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.

EC2: RunInstances' inline BlockDeviceMapping.N.Ebs.* is parsed nowhere and never reaches DescribeVolumes

1 participant