fix(ec2): word an AMI and instance type architecture mismatch as RunInstances does (#8403)

RunInstances already refused an AMI whose architecture the instance type
cannot run, as AWS does, but said "The architecture 'x86_64' of the
specified image does not match the architecture supported by instance
type 'm6g.large'.". AWS names the instance type's architecture first:
"The architecture 'arm64' of the specified instance type does not match
the architecture 'x86_64' of the specified AMI."
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-14 22:33:53 -04:00
1 parent b4fbe99123
commit 246d82ec57
3 files changed
+32 -3

No files matched your search

+5
View File
@@ -94,6 +94,11 @@ The full catalog includes the virtual sizes of `c6g`, `c6gn`, `c7g`, `c8g`,
these same entries. Catalog consumers also use their ARM64 architecture and
CPU/memory capacity for launch validation and container resource limits.
`RunInstances` refuses an AMI whose architecture the instance type cannot run, as
AWS does. An `x86_64` AMI on `m6g.large` answers `InvalidParameterValue` with
`The architecture 'arm64' of the specified instance type does not match the
architecture 'x86_64' of the specified AMI.`, so a Graviton type needs an `arm64` AMI.
The values were captured from AWS `DescribeInstanceTypes` in `us-east-1` on
2026-11-04, including each size's network-card/interface limits and each family's
generation and encryption-in-transit flags. The capture reports C6gn as previous
@@ -4526,13 +4526,18 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
.noneMatch(imageArchitecture.get()::equals))
.ifPresent(type -> {
throw new AwsException("InvalidParameterValue",
"The architecture '" + imageArchitecture.get()
+ "' of the specified image does not match the architecture supported by instance type '"
+ instanceType + "'.",
"The architecture '" + instanceTypeArchitecture(type)
+ "' of the specified instance type does not match the architecture '"
+ imageArchitecture.get() + "' of the specified AMI.",
400);
});
}
/** The architecture RunInstances names for an instance type: x86_64 for a type that also runs i386. */
private static String instanceTypeArchitecture(Ec2InstanceTypeCatalog.CatalogInstanceType type) {
return type.supportedArchitectures.contains("x86_64") ? "x86_64" : type.supportedArchitectures.getFirst();
}
private String architectureFor(String region, String imageId, String instanceType) {
Optional<String> registeredArchitecture = registeredImages.get(key(region, imageId))
.map(Image::getArchitecture);
@@ -3559,6 +3559,25 @@ class Ec2ServiceTest {
assertEquals(reservation.getOwnerId(), reservation.getInstances().getFirst().getOwnerId());
}
@Test
void runInstancesRefusesAnImageWhoseArchitectureTheInstanceTypeCannotRun() {
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
mock(Ec2PortForwardManager.class),
mock(AmiImageResolver.class), new Ec2ImageCatalog(), new Ec2InstanceTypeCatalog(),
new InMemoryStorageFactory());
AwsException graviton = assertThrows(AwsException.class, () -> service.runInstances("us-east-1",
"ami-ubuntu2404-amd64", "m6g.large", 1, 1, null, List.of(), null, null, List.of(), null, null));
AwsException intel = assertThrows(AwsException.class, () -> service.runInstances("us-east-1",
"ami-ubuntu2404-arm64", "t3.micro", 1, 1, null, List.of(), null, null, List.of(), null, null));
assertEquals("InvalidParameterValue", graviton.getErrorCode());
assertEquals("The architecture 'arm64' of the specified instance type does not match the architecture "
+ "'x86_64' of the specified AMI.", graviton.getMessage());
assertEquals("The architecture 'x86_64' of the specified instance type does not match the architecture "
+ "'arm64' of the specified AMI.", intel.getMessage());
}
@Test
void runInstancesKeepsX8664FallbackForUnknownImageAndType() {
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),