diff --git a/docs/services/ec2.md b/docs/services/ec2.md index 7fb1fda699..9821e57f69 100644 --- a/docs/services/ec2.md +++ b/docs/services/ec2.md @@ -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 diff --git a/src/main/java/io/floci/aws/services/ec2/Ec2Service.java b/src/main/java/io/floci/aws/services/ec2/Ec2Service.java index 3a4ca333fd..d96155c98b 100644 --- a/src/main/java/io/floci/aws/services/ec2/Ec2Service.java +++ b/src/main/java/io/floci/aws/services/ec2/Ec2Service.java @@ -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 registeredArchitecture = registeredImages.get(key(region, imageId)) .map(Image::getArchitecture); diff --git a/src/test/java/io/floci/aws/services/ec2/Ec2ServiceTest.java b/src/test/java/io/floci/aws/services/ec2/Ec2ServiceTest.java index cdcb3291b8..1de54e2056 100644 --- a/src/test/java/io/floci/aws/services/ec2/Ec2ServiceTest.java +++ b/src/test/java/io/floci/aws/services/ec2/Ec2ServiceTest.java @@ -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),