Skip to content

EC2: CreateFleet does not apply the aws:ec2:fleet-id tag, so a fleet's instances can't be found #443

Closed

Description

@scttfrdmn

What's missing

Real EC2 tags every instance launched by a fleet with a reserved
aws:ec2:fleet-id tag whose value is the fleet ID. Substrate's CreateFleet
(0.82.0, #387) launches the instances correctly but does not apply that tag, so
there is no way to get from a fleet ID back to its instances.

launchFleetPool (emulator/ec2_fleet.go:429) forwards only the caller's own
TagSpecification entries:

ids, launchErr := p.launchFleetPool(reqCtx, pool, gotPerPool[i], instanceTags)

where instanceTags := passthroughFleetTagSpecs(req.Params, "instance")
(ec2_fleet.go:278). Nothing adds the AWS-injected tag. grep -rn "fleet-id" emulator/*.go
returns nothing.

Why it matters

For an instant fleet, the fleet-id tag is the only supported way to enumerate
current instances. The two obvious alternatives don't work on real AWS:

  • DescribeFleetInstances refuses an instant fleet outright: Unsupported — "Describe fleet instances is not supported by this type of fleet."
  • DescribeFleets returns an Instances list, but it only reflects the original
    launch — it does not drop instances that have since terminated.

So callers that need "what is this fleet still running" filter
DescribeInstances on tag:aws:ec2:fleet-id. That's what
parsl-aws-provider's
get_ec2_fleet_instance_ids() does, and it's the basis of its fleet status
polling — an active instant fleet's FleetState stays active for the fleet's
whole life regardless of what became of the instances, so instance state is the
only real signal.

Against substrate the lookup returns empty, which reads as "the fleet's
instances are all gone" — the opposite of the truth, and a status of COMPLETED
for a fleet that is fully provisioned and running.

Reproduction

import boto3
ec2 = boto3.client("ec2", endpoint_url="http://localhost:4566",
                   region_name="us-west-2",
                   aws_access_key_id="x", aws_secret_access_key="y")
vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"]["VpcId"]
az  = ec2.describe_availability_zones()["AvailabilityZones"][0]["ZoneName"]
sn  = ec2.create_subnet(VpcId=vpc, CidrBlock="10.0.0.0/24", AvailabilityZone=az)["Subnet"]["SubnetId"]
lt  = ec2.create_launch_template(LaunchTemplateName="t",
        LaunchTemplateData={"ImageId": "ami-12345678", "InstanceType": "t3.micro"})["LaunchTemplate"]

f = ec2.create_fleet(
    Type="instant",
    LaunchTemplateConfigs=[{
        "LaunchTemplateSpecification": {"LaunchTemplateId": lt["LaunchTemplateId"], "Version": "1"},
        "Overrides": [{"InstanceType": "t3.micro", "SubnetId": sn}],
    }],
    TargetCapacitySpecification={"TotalTargetCapacity": 2, "DefaultTargetCapacityType": "spot"},
)
fid = f["FleetId"]
ids = [i for g in f["Instances"] for i in g["InstanceIds"]]

d = ec2.describe_instances(InstanceIds=ids)["Reservations"][0]["Instances"][0]
print("tags:", d.get("Tags"))                       # observed: []   expected: aws:ec2:fleet-id=<fid>

found = ec2.describe_instances(
    Filters=[{"Name": "tag:aws:ec2:fleet-id", "Values": [fid]}])["Reservations"]
print("found:", sum(len(r["Instances"]) for r in found))   # observed: 0   expected: 2

Observed on ghcr.io/scttfrdmn/substrate:0.82.0:

tags: []
found: 0

moto 5.1.21 has the same gap, for what it's worth — this isn't a
substrate-vs-moto regression, just something neither emulates.

Suggested fix

In launchFleetPool, add the tag alongside the passthrough ones, using the same
TagSpecification.N.* encoding it already builds for RunInstances. The fleet ID
has to be generated before the launch loop for this (it currently is —
fleet.FleetID = generateFleetID() at ec2_fleet.go:283, before the
for i, pool := range pools loop), so it's available to pass down.

Worth confirming CreateTags also permits the reserved aws: prefix only where
AWS does. Substrate currently accepts create_tags(Tags=[{"Key": "aws:ec2:fleet-id", ...}])
from a client, which real EC2 rejects with
InvalidParameterValue: Tag keys starting with 'aws:' are reserved for internal use.
That's a separate (smaller) fidelity gap, and it's the workaround this project
uses in the meantime, so no rush on tightening it.

Related

Activity

  1. added
    type: bug
    priority: medium
    on Aug 1, 2026
  2. added this to the v0.84.0 milestone on Aug 1, 2026
  3. scttfrdmn commented on Aug 1, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed in #447, shipping in v0.84.0. CreateFleet now stamps aws:ec2:fleet-id on every instance it launches, so your get_ec2_fleet_instance_ids() works against a DescribeInstances tag:aws:ec2:fleet-id filter with no workaround.

    Your diagnosis of why it mattered is what settled the priority: for an instant fleet there is no other route. DescribeFleetInstances rejects instant fleets outright, and the fleetInstanceSet a fleet response echoes is a record of what was launched rather than what is running — it never drops terminated instances. So a fully-provisioned fleet read as empty.

    The tag survives alongside your own launch-time TagSpecification entries (neither overwrites the other — that was the specific regression the index arithmetic could introduce, and it's pinned by a test), and is applied per capacity pool, so a multi-pool fleet tags all of its instances.

    One thing you should know about the evidence, since it affects how much you should trust this. I could not find aws:ec2:fleet-id documented anywhere authoritative: it is not in the EC2 API model, and the fleet tagging/describe/delete user-guide pages are silent on reserved tags — they say only that user tags are not auto-applied. So substrate implements this on your observed real-AWS behaviour, not on a documented API contract. The code comment, the CHANGELOG and docs/services.md all say so explicitly rather than implying a citation. If you ever see real AWS use a different key, that's a bug report worth filing — substrate would be wrong, not just undocumented.

    Also worth acting on now: substrate currently accepts CreateTags with an aws:-prefixed key, which real EC2 rejects (InvalidParameterValue: Tag keys starting with 'aws:' are reserved for internal use). That's a genuine gap on our side, filed as #452. I deliberately did not tighten it in this release, because applying the tag by hand is your current workaround and removing it in the same release that makes it unnecessary would have broken you with no overlap window. It will be tightened a release later — so drop the manual tagging when you pick up v0.84.0 rather than discovering the rejection later.

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

    area: ec2area: taggingpriority: mediumtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions