Skip to content

EC2: launch template NetworkInterfaces is dropped, so template-specified subnets are ignored #444

Closed

Description

@scttfrdmn

What's missing

CreateLaunchTemplate accepts LaunchTemplateData.NetworkInterface.1.* but
stores none of it, so an instance launched from a template that specifies its
networking there lands in a substrate-chosen subnet instead of the requested one.

EC2LaunchTemplateData (emulator/ec2_types.go:604) has no subnet or
network-interface field at all:

type EC2LaunchTemplateData struct {
	ImageID          string   `json:"imageId,omitempty"`
	InstanceType     string   `json:"instanceType,omitempty"`
	KeyName          string   `json:"keyName,omitempty"`
	SecurityGroupIDs []string `json:"securityGroupIds,omitempty"`
	UserData         string   `json:"userData,omitempty"`
}

and createLaunchTemplate (ec2_plugin.go:3967) parses only
LaunchTemplateData.ImageId, .InstanceType, and .SecurityGroupId.N. So the
subnet is dropped at parse time, and runInstances has nothing to resolve: its
launch-template branch (ec2_plugin.go:291-306) copies ImageID,
InstanceType, KeyName, and the first security group, then falls through to
"auto-create default VPC/subnet if none specified".

Note this is specifically the nested form. runInstances already handles a
NetworkInterface.1.SubnetId sent directly on the call (ec2_plugin.go:284-285,
added so spawn's public-IP preference wasn't dropped) — it's the same shape inside
a launch template that's lost.

Why it matters

NetworkInterfaces is the only way a launch template can request a public IP:
AssociatePublicIpAddress exists only inside a network interface spec, and
LaunchTemplateData has no top-level SubnetId member at all (botocore rejects
one). So any template that wants a public IP must put the subnet there too — which
means the subnet is silently lost for exactly the templates that are configured
the way AWS requires.

The failure is quiet and confusing. The launch succeeds, RunInstances returns an
instance, and only a later DescribeInstances filtered on subnet-id reveals
that nothing matches. In
parsl-aws-provider this looked
like "the provider launched no instances" when it had launched them fine; the
tests there now have to find instances by their own ProviderId tag instead of by
subnet, with a comment explaining why.

Reproduction

Same VPC/subnet/SG in all four cases; sn is the requested subnet.

lt = ec2.create_launch_template(LaunchTemplateName="ni", LaunchTemplateData={
    "ImageId": "ami-12345678", "InstanceType": "t3.micro",
    "NetworkInterfaces": [{"DeviceIndex": 0, "SubnetId": sn,
                           "Groups": [sg], "AssociatePublicIpAddress": True}],
})["LaunchTemplate"]

# A) via the template
r = ec2.run_instances(LaunchTemplate={"LaunchTemplateId": lt["LaunchTemplateId"],
                                      "Version": "1"}, MinCount=1, MaxCount=1)
# B) template without NI + call-level SubnetId
# C) CreateFleet with an override SubnetId, same template as A
# D) CreateFleet with no override, template's NI only

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

how the subnet is given lands in requested subnet
A template.NetworkInterfaces[].SubnetId no
B call-level SubnetId yes
C CreateFleet Overrides[].SubnetId yes
D template.NetworkInterfaces[].SubnetId, no override no

C works because launchFleetPool maps the override to a top-level SubnetId
(ec2_fleet.go:453-455), i.e. into the form that already works. A and D are the
gap, and the A-vs-C split is the confusing part: the same template places
instances correctly through CreateFleet and incorrectly through RunInstances.

Also dropped: security groups

DescribeInstances reports no security groups in any of the four cases —
SecurityGroups is absent and NetworkInterfaces is [], even for B where a
call-level SecurityGroupIds=[sg] was accepted. sgID is parsed and stored, so
this may just be a response-shaping omission rather than a modelling one. Happy to
split it out if you'd prefer.

Suggested fix

Add a subnet field (and ideally an AssociatePublicIpAddress flag) to
EC2LaunchTemplateData, parse LaunchTemplateData.NetworkInterface.1.SubnetId /
.Groups.N / .AssociatePublicIpAddress in createLaunchTemplate, and have
runInstances' template branch fall back to them the same way it already falls
back to NetworkInterface.1.SubnetId for a direct call. Precedence on real AWS:
an explicit call-level value wins over the template, and a CreateFleet override
wins over both.

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

    Both halves fixed, shipping in v0.84.0: #448 carries the launch template's network interface to the launch, #449 reports security groups as groupSet.

    One correction worth acting on in your own code. The issue proposes parsing LaunchTemplateData.NetworkInterface.1.Groups.N. Checked against botocore: that member is named Groups in the model but carries locationName: SecurityGroupId, so what real SDKs actually put on the wire is:

    LaunchTemplateData.NetworkInterface.1.SecurityGroupId.N
    

    Substrate accepts both — Groups.N works for hand-built requests — but if you're constructing the form encoding yourself and matching real AWS, SecurityGroupId.N is the one to send.

    Your four-case table was the most useful thing in the report and is now a test verbatim, because it isolated the bug precisely: A and D failed, B and C passed. That asymmetry was the confusing part, and the cause is that the NetworkInterface.1.SubnetId fallback ran before the template resolved — so for A and D there was nothing to fall back to yet. Fixed by consulting the template's networking after resolution and only where the call didn't specify it. B and C are kept as regression guards, since reordering resolution is exactly the change that breaks paths that already worked. (Mutation-tested: removing the fallback fails exactly A and D, leaving B and C green.)

    Also confirmed your read on why this hits templates configured correctly: RequestLaunchTemplateData has no top-level SubnetId member, so a network interface is the only place a template can name a subnet — and the only place AssociatePublicIpAddress exists at all.

    Precedence now follows AWS: request > template > default VPC, with a CreateFleet override winning over the template (it arrives at RunInstances as a request-level value). AssociatePublicIpAddress is stored as a string rather than a bool because three states are observable — absent (use the subnet default), true (force one even on a non-default subnet), false (suppress one) — and collapsing the first two would have lost a real distinction.

    For the groupSet half: groupId and groupName are now emitted by both RunInstances and DescribeInstances, for groups from any source. groupName is omitted when the group can't be resolved — a group deleted after the launch keeps reporting its groupId, since that's what the launch actually recorded, rather than being handed an invented name.

    Two limits from this work are now documented rather than silent, and tracked: only network interface index 1 is modeled (#455), and a launch template is still ignored entirely when ImageId is also passed (#453) — if you pass both today, none of the template's fields are read. Worth knowing before you rely on the merge.

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: vpcpriority: mediumtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions