Light, fluffy, and always free - The AWS Local Emulator alternative
feat(ec2): implement DescribeSpotPriceHistory (#3359)
luisetercee23e26bc377
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2DescribeSpotPriceHistoryTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2DescribeSpotPriceHistoryTest.javanew file mode 100644index 0000000000..b7bd49f9a8--- /dev/null+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Ec2DescribeSpotPriceHistoryTest.java@@ -0,0 +1,45 @@+package com.floci.test;++import org.junit.jupiter.api.Test;+import software.amazon.awssdk.services.ec2.Ec2Client;+import software.amazon.awssdk.services.ec2.model.Ec2Exception;+import software.amazon.awssdk.services.ec2.model.DescribeSpotPriceHistoryRequest;+import software.amazon.awssdk.services.ec2.model.InstanceType;++import java.time.Instant;++import static org.assertj.core.api.Assertions.assertThat;+import static org.junit.jupiter.api.Assertions.assertThrows;++class Ec2DescribeSpotPriceHistoryTest {++ @Test+ void describeSpotPriceHistoryReturnsEmptyHistoryWhenNoSnapshotIsConfigured() {+ try (Ec2Client ec2 = TestFixtures.ec2Client()) {+ var response = ec2.describeSpotPriceHistory(DescribeSpotPriceHistoryRequest.builder()+ .instanceTypes(InstanceType.M5_LARGE, InstanceType.fromValue("t4g.medium"))+ .productDescriptions("Linux/UNIX")+ .availabilityZone("us-east-1a")+ .startTime(Instant.parse("2026-01-01T00:00:00Z"))+ .endTime(Instant.parse("2026-01-02T00:00:00Z"))+ .maxResults(100)+ .build());++ assertThat(response.spotPriceHistory()).isEmpty();+ assertThat(response.nextToken()).isEmpty();+ }+ }++ @Test+ void describeSpotPriceHistoryHonorsDryRun() {+ try (Ec2Client ec2 = TestFixtures.ec2Client()) {+ Ec2Exception exception = assertThrows(Ec2Exception.class,+ () -> ec2.describeSpotPriceHistory(DescribeSpotPriceHistoryRequest.builder()+ .dryRun(true)+ .build()));++ assertThat(exception.statusCode()).isEqualTo(412);+ assertThat(exception.awsErrorDetails().errorCode()).isEqualTo("DryRunOperation");+ }+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.javaindex 78241e481a..01e0bef235 100644--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java@@ -171,7 +171,7 @@ public class AwsQueryController {"DescribeAddressesAttribute","DescribeIamInstanceProfileAssociations","DescribeAvailabilityZones", "DescribeRegions", "DescribeAccountAttributes",- "DescribeInstanceTypes", "DescribeInstanceTypeOfferings",+ "DescribeInstanceTypes", "DescribeInstanceTypeOfferings", "DescribeSpotPriceHistory","CreateLaunchTemplate", "CreateLaunchTemplateVersion", "DescribeLaunchTemplates", "DescribeLaunchTemplateVersions","ModifyLaunchTemplate", "DeleteLaunchTemplate","DescribeNetworkInterfaces",diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.javaindex bb55b895d4..bf2a18745e 100644--- a/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/ec2/Ec2QueryHandler.java@@ -256,6 +256,7 @@ public class Ec2QueryHandler {case "RequestSpotInstances" -> handleRequestSpotInstances(params, region);case "DescribeSpotInstanceRequests" -> handleDescribeSpotInstanceRequests(params, region);case "CancelSpotInstanceRequests" -> handleCancelSpotInstanceRequests(params, region);+ case "DescribeSpotPriceHistory" -> handleDescribeSpotPriceHistory(params, region);// IPAMcase "EnableIpamOrganizationAdminAccount" -> handleEnableIpamOrgAdmin(params);case "DisableIpamOrganizationAdminAccount" -> handleDisableIpamOrgAdmin(params);@@ -5376,6 +5377,25 @@ public class Ec2QueryHandler {return xmlResponse(xml.build());}+ /**+ * Return the EC2 Query response shape for spot price history.+ *+ * <p>Floci does not currently maintain a spot-price snapshot. AWS returns an empty+ * {@code spotPriceHistorySet} when no matching records exist, which is sufficient for+ * clients such as Karpenter to distinguish an empty result from an unsupported action.</p>+ */+ private Response handleDescribeSpotPriceHistory(MultivaluedMap<String, String> p, String region) {+ checkDryRun(p);+ XmlBuilder xml = new XmlBuilder()+ .start("DescribeSpotPriceHistoryResponse", AwsNamespaces.EC2)+ .elem("requestId", UUID.randomUUID().toString())+ .elem("nextToken", "")+ .start("spotPriceHistorySet")+ .end("spotPriceHistorySet")+ .end("DescribeSpotPriceHistoryResponse");+ return xmlResponse(xml.build());+ }+private String spotInstanceRequestXml(SpotInstanceRequest sir) {XmlBuilder xml = new XmlBuilder().elem("spotInstanceRequestId", sir.getSpotInstanceRequestId())