Skip to content

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

Closed

Description

@scttfrdmn

Summary

RunInstances' inline BlockDeviceMapping.N.Ebs.* parameters (root/additional volume specs given at launch time, as opposed to a separate CreateVolume call) are parsed nowhere in emulator/ec2_plugin.go's runInstancesWithTags, and never populate the volume: state namespace that DescribeVolumes (added for #256) reads from. So a launch that specifies BlockDeviceMapping.1.Ebs.VolumeSize=60 produces an instance with no discoverable volume at all — DescribeVolumes returns zero results for it, and DescribeInstanceAttribute with blockDeviceMapping is explicitly rejected (grep confirms no such attribute case exists).

Confirmed via source inspection against v0.102.0 (latest):

  • grep -n "BlockDeviceMapping\." emulator/ec2_plugin.go (excluding tests) shows exactly one read site, BlockDeviceMapping.N.Ebs.SnapshotId, used only for AMI-registration snapshot lookup (~line 3263) — not called from runInstancesWithTags.
  • runInstancesWithTags (~line 280) parses ImageId, InstanceType, counts, KeyName, IAM profile, UserData, DisableApiTermination, placement, subnet/SG, network interfaces — no BlockDeviceMapping.* of any kind.
  • describeVolumes (~line 4724) lists only from p.state.List(ctx, ec2Namespace, "volume:"+account+"/"+region+"/") — the namespace CreateVolume (EC2: Add EBS volume operations (CreateVolume, DescribeVolumes, AttachVolume, DetachVolume, DeleteVolume, DeleteSnapshot) #256) writes to, and nothing else does.

Also confirmed empirically from a consumer (spawn, spore-host/spawn#544's fix PR): a real launch with a custom root volume size followed immediately by DescribeVolumes against the Substrate emulator (pinned v0.97.0, same gap present) returned zero volumes for the instance.

Impact

Any test asserting "the instance I just launched has a root volume of size X" (the natural way to verify a root-volume-size feature, since AWS represents this on the instance's own block device mapping, not as a separate resource) has no queryable state to assert against — despite RunInstances accepting and silently discarding the parameter.

Expected behavior

RunInstances should parse BlockDeviceMapping.N.{DeviceName,Ebs.VolumeSize,Ebs.VolumeType,Ebs.SnapshotId,Ebs.DeleteOnTermination,Ebs.Encrypted,Ebs.Iops,Ebs.Throughput} (repeated, 1-indexed, same convention as the existing NetworkInterface.N/Filter.N parsing elsewhere in this file) and, for each, create a synthetic volume record in the same volume: namespace CreateVolume uses — in-use, attached to the new instance at the given device name, sized/typed per the request (falling back to an AMI-appropriate default, e.g. 8 GiB gp3, when VolumeSize is omitted — mirroring real EC2's "root volume defaults to the AMI snapshot size" behavior). This makes DescribeVolumes (filtered by attachment.instance-id) the single source of truth for both CreateVolume-provisioned and launch-time-specified volumes, matching how real EC2 unifies the two.

A minimal version — just recording VolumeSize per device and making it visible via DescribeVolumes — would already close the gap that matters most (verifying a requested volume size actually took effect); full parity on every Ebs.* sub-field (IOPS, throughput, encryption) can follow the existing volume-plugin's granularity if that's more work than warranted right now.

Repro

RunInstances ... &BlockDeviceMapping.1.DeviceName=/dev/xvda&BlockDeviceMapping.1.Ebs.VolumeSize=60
# -> instance launches successfully
DescribeVolumes --filters Name=attachment.instance-id,Values=<id>
# -> <volumeSet/> (empty), regardless of VolumeSize requested

Related

Activity

  1. added this to the v0.103.0 milestone on Aug 20, 2026
  2. scttfrdmn commented on Aug 20, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed in #668, shipping in v0.103.0.

    Your framing was exactly right, and worth restating because it is why this could not be
    fixed by exposing the mapping on the instance: AWS's EbsInstanceBlockDevice — the shape
    DescribeInstances renders per device — carries volumeId, attachTime,
    deleteOnTermination and status, and no size. DescribeVolumes is the only API
    surface on which a launch-specified size is observable at all, so the 60 GiB you asked for
    was not merely hidden, it was unreachable. A launch now materializes real volumes in the
    same store CreateVolume writes to.

    Two decisions in the fix are worth flagging, since neither is what a reader would guess.

    Every RunInstances now produces at least one volume. A real instance always has a
    root volume whether or not the request mentions one, and substrate's DescribeImages
    already reported an 8 GiB /dev/sda1 mapping for every AMI it serves — so producing none
    left those two APIs disagreeing about the same instance. A launch declaring no mapping now
    gets a synthesized 8 GiB gp2 volume at /dev/sda1.

    The compatibility cost is real and accepted: a test that listed all volumes and
    expected only what it created with CreateVolume will now see a root volume per launched
    instance. Filter by volume-id or attachment.instance-id for the old answer.

    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"). That detail
    mattered for your repro specifically: a rule recognizing only /dev/sda1 would have
    answered /dev/xvda + 60 with two volumes, yours plus a spurious 8 GiB root.

    DeleteOnTermination defaults to true for data volumes too. Counter-intuitive, and
    it comes straight from AWS's preserving-volumes-on-termination table, which splits on
    how the volume was attached rather than on what it is: a data volume attached at launch
    through the console preserves, but through the CLI/API it is deleted. An API
    emulator only has the CLI path, so every volume a launch creates defaults to true, and
    AttachVolume keeps the other default, false — deleting a volume you brought would
    destroy something the launch did not make.

    TerminateInstances now honors that, which is what made the parsing safe to land at all.
    Without it a volume would report deleteOnTermination=true while sitting in-use on a
    terminated instance forever — a state real EC2 never reaches, and a new inaccuracy in
    place of the old silence.

    Also in the fix: iops and throughput now reach the wire (IOPS was stored and never
    rendered; throughput had nowhere to be stored), DescribeVolumes gained the
    attachment.device, attachment.delete-on-termination, volume-type, size,
    availability-zone and snapshot-id filters, and a fleet reaches mappings through its
    launch template, which now carries them.

    Deliberately out of scope, filed as follow-ups: blockDeviceMapping on
    DescribeInstances/DescribeInstanceAttribute (the shape carries no size, so it would not
    answer this question), volume tag specifications (a CreateVolume parity gap),
    Ebs.KmsKeyId, and InvalidBlockDeviceMapping validation — which needed this state to
    exist before it could be checked against anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions