Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(servicequotas): report the standard EC2 quota default (#5778)

David Phillips167336fc73cc
diff --git a/compatibility-tests/sdk-test-java/pom.xml b/compatibility-tests/sdk-test-java/pom.xml
index 5633c15a20..993ed75d33 100644
--- a/compatibility-tests/sdk-test-java/pom.xml
+++ b/compatibility-tests/sdk-test-java/pom.xml
@@ -72,6 +72,10 @@
</dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>software.amazon.awssdk</groupId>
+ <artifactId>servicequotas</artifactId>
+ </dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>acm</artifactId>
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
index 3fb67fb84c..79412b78b6 100644
--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
@@ -142,6 +142,7 @@ import software.amazon.awssdk.services.scheduler.SchedulerClient;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.securityhub.SecurityHubClient;
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient;
+import software.amazon.awssdk.services.servicequotas.ServiceQuotasClient;
import software.amazon.awssdk.services.ses.SesClient;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest;
@@ -553,6 +554,14 @@ public final class TestFixtures {
.build();
}
+ public static ServiceQuotasClient serviceQuotasClient() {
+ return ServiceQuotasClient.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(CREDENTIALS)
+ .build();
+ }
+
public static MarketplaceCatalogClient marketplaceCatalogClient() {
return MarketplaceCatalogClient.builder()
.endpointOverride(ENDPOINT)
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ServiceQuotasTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ServiceQuotasTest.java
new file mode 100644
index 0000000000..e507479f7b
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/ServiceQuotasTest.java
@@ -0,0 +1,60 @@
+package com.floci.test;
+
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.servicequotas.ServiceQuotasClient;
+import software.amazon.awssdk.services.servicequotas.model.ServiceQuota;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+
+class ServiceQuotasTest {
+
+ private static final String STANDARD_CODE = "L-1216C47A";
+
+ @Test
+ void standardEc2DefaultQuotaUsesCanonicalMetadata() {
+ assumeFalse(TestFixtures.isRealAws(), "Tests the emulated static quota catalog");
+ try (ServiceQuotasClient client = TestFixtures.serviceQuotasClient()) {
+ ServiceQuota quota = client.getAWSDefaultServiceQuota(request -> request
+ .serviceCode("ec2").quotaCode(STANDARD_CODE)).quota();
+ assertStandardMetadata(quota);
+ List<List<ServiceQuota>> pages = client.listAWSDefaultServiceQuotasPaginator(request -> request
+ .serviceCode("ec2").maxResults(1)).stream().map(page -> page.quotas()).toList();
+ assertCatalogPages(pages, quota);
+ }
+ }
+
+ @Test
+ void emulatedAppliedQuotaReportsTheStaticDefault() {
+ assumeFalse(TestFixtures.isRealAws(), "Real applied quotas can differ from catalog defaults");
+ try (ServiceQuotasClient client = TestFixtures.serviceQuotasClient()) {
+ ServiceQuota quota = client.getServiceQuota(request -> request
+ .serviceCode("ec2").quotaCode(STANDARD_CODE)).quota();
+ assertStandardMetadata(quota);
+ List<List<ServiceQuota>> pages = client.listServiceQuotasPaginator(request -> request
+ .serviceCode("ec2").maxResults(1)).stream().map(page -> page.quotas()).toList();
+ assertCatalogPages(pages, quota);
+ }
+ }
+
+ private static void assertCatalogPages(List<List<ServiceQuota>> pages, ServiceQuota standardQuota) {
+ assertThat(pages).hasSize(4).allSatisfy(page -> assertThat(page).hasSize(1));
+ List<ServiceQuota> quotas = pages.stream().flatMap(List::stream).toList();
+ assertThat(quotas).extracting(ServiceQuota::quotaCode).doesNotHaveDuplicates();
+ assertThat(quotas.stream().filter(item -> STANDARD_CODE.equals(item.quotaCode())).toList())
+ .containsExactly(standardQuota);
+ }
+
+ private static void assertStandardMetadata(ServiceQuota quota) {
+ assertThat(quota).isNotNull();
+ assertThat(quota.serviceCode()).isEqualTo("ec2");
+ assertThat(quota.quotaCode()).isEqualTo(STANDARD_CODE);
+ assertThat(quota.quotaName())
+ .isEqualTo("Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances");
+ assertThat(quota.value()).isEqualTo(5.0);
+ assertThat(quota.adjustable()).isTrue();
+ assertThat(quota.globalQuota()).isFalse();
+ }
+}
diff --git a/docs/services/servicequotas.md b/docs/services/servicequotas.md
index 8bd4ae3902..e0f0774251 100644
--- a/docs/services/servicequotas.md
+++ b/docs/services/servicequotas.md
@@ -7,13 +7,16 @@
Floci answers Service Quotas lookups from a generated in-memory catalog. Every service code
resolves to a quota list: a curated set with real AWS quota codes where tooling depends on
them — CodeBuild's `L-2DC20C30` ("Concurrently running builds") and Lambda's `L-B99A9384`
-("Concurrent executions") — plus a deterministic generic set for any other service code. All
-values are deliberately generous so local pipelines that gate on quota headroom, such
+("Concurrent executions") — plus a deterministic generic set for any other service code.
+Unmodeled values are deliberately generous so local pipelines that gate on quota headroom, such
as AWS Landing Zone Accelerator, never stall on a limit the emulator does not enforce. The
Organizations `Maximum number of accounts` quota uses AWS quota code `L-E619E033` and a local value
of 50. VPC's `L-FE5A380F` ("NAT gateways per Availability Zone", 5) and `L-2AEEBF1A` ("Rules per
network ACL", 20) carry their AWS default values, so tooling that compares a desired value against
the default before requesting an increase takes the same path it would against AWS.
+EC2's `L-1216C47A` ("Running On-Demand Standard (A, C, D, H, I, M, R, T, Z)
+instances") also reports its AWS default of 5. This catalog entry does not enforce
+a vCPU admission limit on EC2.
Applied quotas and AWS default quotas return the same data, and quota values are static.
`RequestServiceQuotaIncrease` is accepted and validated, records the request, and lets you read
diff --git a/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java b/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java
index 0f0e8bcc89..dcbdb369e1 100644
--- a/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasService.java
@@ -29,9 +29,9 @@ import java.util.zip.CRC32;
* quota codes where tooling depends on them (CodeBuild's {@code L-2DC20C30}
* "Concurrently running builds", Lambda's {@code L-B99A9384} "Concurrent
* executions"), plus a deterministic generic set for any other service code.
- * All values are deliberately generous so local pipelines that gate on quota
- * headroom (for example Landing Zone Accelerator) never stall on a limit the
- * emulator does not enforce. Applied and default quotas return the same data.
+ * Unmodeled values are deliberately generous so local pipelines that gate on
+ * quota headroom never stall on a limit the emulator does not enforce.
+ * Applied and default quotas return the same data.
*
* @see <a href="https://docs.aws.amazon.com/servicequotas/2019-06-24/apireference/Welcome.html">Service Quotas API</a>
*/
@@ -66,6 +66,9 @@ public class ServiceQuotasService {
new QuotaDefinition("L-B99A9384", "Concurrent executions", GENERIC_QUOTA_VALUE, false)),
"organizations", List.of(
new QuotaDefinition("L-E619E033", "Maximum number of accounts", 50.0, true)),
+ "ec2", List.of(
+ new QuotaDefinition("L-1216C47A",
+ "Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances", 5.0, false)),
// AWS default values: tooling such as Terraform's aws_servicequotas_service_quota
// compares its desired value against these before requesting an increase.
"vpc", List.of(
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasIntegrationTest.java
index 253cd29150..5c21b86f97 100644
--- a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasIntegrationTest.java
@@ -6,6 +6,8 @@ import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import java.util.List;
@@ -182,6 +184,82 @@ class ServiceQuotasIntegrationTest {
.body("Quota.GlobalQuota", equalTo(true));
}
+ @ParameterizedTest
+ @CsvSource(value = {"us-east-1|111111111111|aws", "cn-north-1|333333333333|aws-cn"}, delimiter = '|')
+ void ec2StandardQuotaUsesAwsCodeAndRegionalOwner(String region, String account, String partition) {
+ String code = "L-1216C47A";
+ String name = "Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances";
+ String authorization = "AWS4-HMAC-SHA256 Credential=" + account + "/20261015/"
+ + region + "/servicequotas/aws4_request";
+ for (String action : List.of("GetServiceQuota", "GetAWSDefaultServiceQuota")) {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "ServiceQuotasV20190624." + action)
+ .header("Authorization", authorization)
+ .body("{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"" + code + "\"}")
+ .when().post("/")
+ .then().log().ifValidationFails().statusCode(200)
+ .body("Quota.QuotaCode", equalTo(code))
+ .body("Quota.QuotaName", equalTo(name))
+ .body("Quota.Value", equalTo(5.0f))
+ .body("Quota.Adjustable", equalTo(true))
+ .body("Quota.GlobalQuota", equalTo(false))
+ .body("Quota.QuotaAppliedAtLevel", equalTo("ACCOUNT"))
+ .body("Quota.QuotaArn", equalTo("arn:" + partition + ":servicequotas:" + region + ":"
+ + account + ":ec2/" + code));
+ }
+ for (String action : List.of("ListServiceQuotas", "ListAWSDefaultServiceQuotas")) {
+ given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "ServiceQuotasV20190624." + action)
+ .header("Authorization", authorization)
+ .body("{\"ServiceCode\":\"ec2\",\"MaxResults\":100}")
+ .when().post("/")
+ .then().log().ifValidationFails().statusCode(200)
+ .body("Quotas.find { it.QuotaCode == 'L-1216C47A' }.QuotaName", equalTo(name))
+ .body("Quotas.find { it.QuotaCode == 'L-1216C47A' }.Value", equalTo(5.0f))
+ .body("Quotas.size()", equalTo(4));
+ }
+ }
+
+ @ParameterizedTest
+ @CsvSource({"us-east-1,aws", "cn-north-1,aws-cn"})
+ void ec2IncreaseRequestsRemainIsolatedByAccount(String region, String partition) {
+ String firstAccount = "111111111111";
+ String secondAccount = "333333333333";
+ String requestBody = "{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"L-1216C47A\",\"DesiredValue\":10}";
+ String firstId = quotaRequest("RequestServiceQuotaIncrease", requestBody, region, firstAccount)
+ .then().statusCode(200)
+ .body("RequestedQuota.QuotaArn", equalTo("arn:" + partition + ":servicequotas:" + region
+ + ":" + firstAccount + ":ec2/L-1216C47A"))
+ .extract().path("RequestedQuota.Id");
+ String secondId = quotaRequest("RequestServiceQuotaIncrease", requestBody, region, secondAccount)
+ .then().statusCode(200)
+ .body("RequestedQuota.QuotaArn", equalTo("arn:" + partition + ":servicequotas:" + region
+ + ":" + secondAccount + ":ec2/L-1216C47A"))
+ .extract().path("RequestedQuota.Id");
+ assertNotEquals(firstId, secondId);
+ for (String account : List.of(firstAccount, secondAccount)) {
+ String ownId = account.equals(firstAccount) ? firstId : secondId;
+ String otherId = account.equals(firstAccount) ? secondId : firstId;
+ quotaRequest("RequestServiceQuotaIncrease", requestBody, region, account)
+ .then().statusCode(400).body("__type", equalTo("ResourceAlreadyExistsException"));
+ quotaRequest("ListRequestedServiceQuotaChangeHistoryByQuota",
+ "{\"ServiceCode\":\"ec2\",\"QuotaCode\":\"L-1216C47A\"}", region, account)
+ .then().statusCode(200).body("RequestedQuotas.Id", equalTo(List.of(ownId)));
+ quotaRequest("GetRequestedServiceQuotaChange", "{\"RequestId\":\"" + ownId + "\"}", region, account)
+ .then().statusCode(200).body("RequestedQuota.Id", equalTo(ownId));
+ quotaRequest("GetRequestedServiceQuotaChange", "{\"RequestId\":\"" + otherId + "\"}", region, account)
+ .then().statusCode(400).body("__type", equalTo("NoSuchResourceException"));
+ }
+ }
+
+ private Response quotaRequest(String action, String body, String region, String account) {
+ return given().contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "ServiceQuotasV20190624." + action)
+ .header("Authorization", "AWS4-HMAC-SHA256 Credential=" + account
+ + "/20261016/" + region + "/servicequotas/aws4_request")
+ .body(body).when().post("/");
+ }
+
@Test
void vpcQuotasUseAwsQuotaCodesAsDefaultAndApplied() {
for (String target : new String[] {"GetAWSDefaultServiceQuota", "GetServiceQuota"}) {
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java
index 4b027d34d5..d4d2a6bd93 100644
--- a/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/servicequotas/ServiceQuotasServiceTest.java
@@ -11,7 +11,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -41,6 +43,33 @@ class ServiceQuotasServiceTest {
}
}
+ @Test
+ void ec2StandardQuotaRetainsCanonicalMetadataWhenListingAndReading() {
+ String code = "L-1216C47A";
+ String name = "Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances";
+ JsonNode quota = assertDoesNotThrow(() ->
+ service.getServiceQuota("ec2", code, "us-east-1", ACCOUNT_ID)).path("Quota");
+ assertEquals(code, quota.path("QuotaCode").asText());
+ assertEquals(name, quota.path("QuotaName").asText());
+ assertEquals(5.0, quota.path("Value").asDouble());
+ assertTrue(quota.path("Adjustable").asBoolean());
+ assertTrue(quota.path("GlobalQuota").isBoolean());
+ assertFalse(quota.path("GlobalQuota").asBoolean());
+ assertEquals("ACCOUNT", quota.path("QuotaAppliedAtLevel").asText());
+ assertEquals("arn:aws:servicequotas:us-east-1:" + ACCOUNT_ID + ":ec2/" + code,
+ quota.path("QuotaArn").asText());
+ JsonNode listed = service.listServiceQuotas("ec2", null, null, 100, "us-east-1", ACCOUNT_ID).path("Quotas");
+ assertEquals(4, listed.size());
+ int matching = 0;
+ for (JsonNode entry : listed) {
+ if (code.equals(entry.path("QuotaCode").asText())) {
+ assertEquals(quota, entry);
+ matching++;
+ }
+ }
+ assertEquals(1, matching);
+ }
+
@Test
void codebuildIncludesConcurrentlyRunningBuilds() {
List<String> codes = service.quotasFor("codebuild").stream()