Repository navigation
Description
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 onlyObserved 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
- CFN: LaunchTemplate, InstanceProfile, SecurityGroupIngress fall to generic stub despite handlers existing #388 (CFN
LaunchTemplatefell to a generic stub) is adjacent but distinct —
this is the EC2 API path, not CloudFormation. - EC2: CreateFleet does not apply the aws:ec2:fleet-id tag, so a fleet's instances can't be found #443 — the other
CreateFleetfidelity gap found in the same sweep.
Activity
fix(ec2): carry a launch template's network interface to the launch (#…
fix(ec2): report an instance's security groups as groupSet (#444) (#449)
scttfrdmn commentedon Aug 1, 2026
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 namedGroupsin the model but carrieslocationName: SecurityGroupId, so what real SDKs actually put on the wire is:Substrate accepts both —
Groups.Nworks for hand-built requests — but if you're constructing the form encoding yourself and matching real AWS,SecurityGroupId.Nis 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.SubnetIdfallback 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:
RequestLaunchTemplateDatahas no top-levelSubnetIdmember, so a network interface is the only place a template can name a subnet — and the only placeAssociatePublicIpAddressexists at all.Precedence now follows AWS: request > template > default VPC, with a
CreateFleetoverride winning over the template (it arrives atRunInstancesas a request-level value).AssociatePublicIpAddressis 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
groupSethalf:groupIdandgroupNameare now emitted by bothRunInstancesandDescribeInstances, for groups from any source.groupNameis omitted when the group can't be resolved — a group deleted after the launch keeps reporting itsgroupId, 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
ImageIdis also passed (#453) — if you pass both today, none of the template's fields are read. Worth knowing before you rely on the merge.chore(release): v0.84.0 (#451)
fix(ec2): merge a launch template with request-level parameters (#453) (
feat(ec2): an instance reports its own block devices (#669) (#679)