feat(ec2): implement instant CreateFleet (#2956)

* feat(ec2): implement instant CreateFleet

* fix(ec2): address CreateFleet review feedback

* fix(ec2): harden CreateFleet placement rollback

* test(ec2): isolate CreateFleet dry-run fixture

* fix(ec2): group CreateFleet response instances

* fix(ec2): report incomplete fleet rollback

* fix(ec2): resolve fleet placement from subnet overrides
This commit is contained in:
luiseterc authored and GitHub committed 2026-09-04 10:06:44 -04:00
1 parent a7be2dd299
commit 1f87f7c482
7 files changed
+695 -2

No files matched your search

@@ -7,6 +7,8 @@ import software.amazon.awssdk.services.ec2.model.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.assertj.core.api.Assertions.*;
@@ -14,6 +16,7 @@ import static org.assertj.core.api.Assertions.*;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class Ec2Tests {
private static final Logger LOG = Logger.getLogger(Ec2Tests.class.getName());
private static Ec2Client ec2;
private static String vpcId;
private static String subnetId;
@@ -24,6 +27,7 @@ class Ec2Tests {
private static String rtbAssocId;
private static String allocationId;
private static String instanceId;
private static String fleetInstanceId;
@BeforeAll
static void setup() {
@@ -34,6 +38,13 @@ class Ec2Tests {
@AfterAll
static void cleanup() {
if (ec2 != null) {
try {
if (fleetInstanceId != null) {
ec2.terminateInstances(TerminateInstancesRequest.builder().instanceIds(fleetInstanceId).build());
}
} catch (Exception e) {
LOG.log(Level.WARNING, "Failed to terminate CreateFleet test instance " + fleetInstanceId, e);
}
try {
if (instanceId != null) {
ec2.terminateInstances(TerminateInstancesRequest.builder().instanceIds(instanceId).build());
@@ -223,6 +234,58 @@ class Ec2Tests {
.containsExactly("arm64");
}
@Test
@Order(7)
@DisplayName("CreateFleet - dry-run and instant on-demand launch")
void createFleetDryRunAndLaunch() {
String launchTemplateId = ec2.createLaunchTemplate(CreateLaunchTemplateRequest.builder()
.launchTemplateName("sdk-create-fleet")
.launchTemplateData(RequestLaunchTemplateData.builder()
.imageId("ami-0abcdef1234567890")
.instanceType(InstanceType.T3_MICRO)
.build())
.build()).launchTemplate().launchTemplateId();
FleetLaunchTemplateConfigRequest config = FleetLaunchTemplateConfigRequest.builder()
.launchTemplateSpecification(FleetLaunchTemplateSpecificationRequest.builder()
.launchTemplateId(launchTemplateId)
.version("1")
.build())
.overrides(FleetLaunchTemplateOverridesRequest.builder()
.instanceType(InstanceType.T3_MICRO)
.imageId("ami-0abcdef1234567890")
.build())
.build();
CreateFleetRequest request = CreateFleetRequest.builder()
.type(FleetType.INSTANT)
.launchTemplateConfigs(config)
.targetCapacitySpecification(TargetCapacitySpecificationRequest.builder()
.totalTargetCapacity(1)
.defaultTargetCapacityType(DefaultTargetCapacityType.ON_DEMAND)
.build())
.build();
try {
assertThatThrownBy(() -> ec2.createFleet(request.toBuilder().dryRun(true).build()))
.isInstanceOf(Ec2Exception.class)
.satisfies(error -> assertThat(((Ec2Exception) error).awsErrorDetails().errorCode())
.isEqualTo("DryRunOperation"));
CreateFleetResponse response = ec2.createFleet(request);
assertThat(response.fleetId()).startsWith("fleet-");
assertThat(response.instances()).hasSize(1);
assertThat(response.instances().get(0).instanceIds()).hasSize(1);
fleetInstanceId = response.instances().get(0).instanceIds().get(0);
assertThat(response.instances().get(0).instanceType()).isEqualTo(InstanceType.T3_MICRO);
assertThat(response.instances().get(0).lifecycle()).isEqualTo(InstanceLifecycle.ON_DEMAND);
}
finally {
ec2.deleteLaunchTemplate(DeleteLaunchTemplateRequest.builder()
.launchTemplateId(launchTemplateId)
.build());
}
}
@Test
@Order(8)
@DisplayName("CreateVpc - create VPC with CIDR")