feat(lambda): list provisioned concurrency configurations (#6758)

* feat(lambda): list provisioned concurrency configurations

Dispatch List=ALL to a paginated view of existing provisioned concurrency allocations. Preserve qualified ARNs, current status and existing pool lifecycle.

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

* fix(lambda): share function ARN region resolution

Share the existing Lambda region validation and error message across function resolution and provisioned-concurrency lookup/listing.

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

---------

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-27 18:13:24 -04:00
1 parent c37e0aaba9
commit b6d9e4c7a4
10 files changed
+354 -19

No files matched your search

@@ -10,6 +10,29 @@ import static org.junit.jupiter.api.Assertions.*;
class LambdaArnUtilsTest {
@ParameterizedTest
@ValueSource(strings = {"my-fn", "111111111111:function:my-fn",
"arn:aws:lambda:us-east-1:111111111111:function:my-fn"})
void resolveWithRegionKeepsAccountAndQualifier(String input) {
LambdaArnUtils.ResolvedFunctionRef original = LambdaArnUtils.resolveWithQualifier(input, "live");
assertEquals(original, LambdaArnUtils.resolveWithRegion("us-east-1", input, "live"));
}
@Test
void resolveWithRegionRejectsMismatchAfterQualifierValidation() {
String arn = "arn:aws-cn:lambda:cn-north-1:111111111111:function:my-fn:live";
AwsException mismatch = assertThrows(AwsException.class,
() -> LambdaArnUtils.resolveWithRegion("cn-northwest-1", arn, "live"));
assertEquals("InvalidParameterValueException", mismatch.getErrorCode());
assertEquals(400, mismatch.getHttpStatus());
assertEquals("Region 'cn-north-1' in ARN does not match request region 'cn-northwest-1'",
mismatch.getMessage());
AwsException qualifier = assertThrows(AwsException.class,
() -> LambdaArnUtils.resolveWithRegion("cn-northwest-1", arn, "other"));
assertEquals("The derived qualifier from the function name does not match the specified qualifier.",
qualifier.getMessage());
}
@ParameterizedTest
@CsvSource({
// input, expectedName, expectedQualifier, expectedRegion, expectedAccount
@@ -1,12 +1,15 @@
package io.github.hectorvent.floci.services.lambda;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.*;
@@ -46,6 +49,28 @@ class LambdaProvisionedConcurrencyIntegrationTest {
verify(pool).delete(anyString(), eq("example"), eq("live"), anyString());
}
@Test
void listUsesItsOwnOperationAndRendersQualifiedConfigurationsAndMarker() {
String arn = "arn:aws:lambda:us-east-1:111111111111:function:example:live";
ProvisionedConcurrencyPool.Status status = new ProvisionedConcurrencyPool.Status(
2, 0, 0, "FAILED", "initialization failed", "2026-01-01T00:00:00+0000");
when(pool.list(anyString(), eq("example"), anyString(), eq("1"), eq("previous")))
.thenReturn(new PaginatedResult<>(List.of(
new ProvisionedConcurrencyPool.ListedConfiguration(arn, status)), "next"));
given().queryParam("List", "ALL").queryParam("MaxItems", "1").queryParam("Marker", "previous")
.get(PATH).then().statusCode(200)
.body("NextMarker", equalTo("next"))
.body("ProvisionedConcurrencyConfigs.size()", equalTo(1))
.body("ProvisionedConcurrencyConfigs[0].FunctionArn", equalTo(arn))
.body("ProvisionedConcurrencyConfigs[0].Status", equalTo("FAILED"))
.body("ProvisionedConcurrencyConfigs[0].StatusReason", equalTo("initialization failed"))
.body("ProvisionedConcurrencyConfigs[0].RequestedProvisionedConcurrentExecutions", equalTo(2))
.body("ProvisionedConcurrencyConfigs[0].AllocatedProvisionedConcurrentExecutions", equalTo(0))
.body("ProvisionedConcurrencyConfigs[0].AvailableProvisionedConcurrentExecutions", equalTo(0))
.body("ProvisionedConcurrencyConfigs[0].LastModified", equalTo("2026-01-01T00:00:00+0000"));
verify(pool, never()).get(any(), any(), any(), any());
}
@Test
void missingConfigurationUsesTheModeledAwsException() {
when(pool.get(anyString(), eq("example"), eq("live"), anyString()))
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.lambda;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.lambda.model.LambdaAlias;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
@@ -15,6 +16,7 @@ import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@QuarkusTest
class LambdaProvisionedConcurrencyNotFoundIntegrationTest {
@@ -66,6 +68,33 @@ class LambdaProvisionedConcurrencyNotFoundIntegrationTest {
}
}
@Test
void listRejectsAnotherRegionWithTheSharedLambdaError() {
String arn = AwsArnUtils.Arn.of("lambda", "us-west-2", resolver.getAccountId(),
"function:" + NAME).toString();
given().queryParam("List", "ALL").pathParam("function", arn)
.get("/2019-09-30/functions/{function}/provisioned-concurrency")
.then().statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"))
.body("message", equalTo("Region 'us-west-2' in ARN does not match request region '"
+ resolver.getRegion() + "'"));
}
@Test
void targetOperationsRejectAnotherRegionWithTheSharedLambdaError() {
String arn = AwsArnUtils.Arn.of("lambda", "us-west-2", resolver.getAccountId(),
"function:" + NAME + ":live").toString();
for (String method : List.of("GET", "PUT", "DELETE")) {
given().contentType("application/json").queryParam("Qualifier", "live")
.pathParam("function", arn).body("{\"ProvisionedConcurrentExecutions\":1}")
.request(method, "/2019-09-30/functions/{function}/provisioned-concurrency")
.then().statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"))
.body("message", equalTo("Region 'us-west-2' in ARN does not match request region '"
+ resolver.getRegion() + "'"));
}
}
@Test
void existingAliasAndVersionRetainTheirConfigurationBehavior() {
for (String qualifier : List.of("live", "1")) {
@@ -77,6 +106,32 @@ class LambdaProvisionedConcurrencyNotFoundIntegrationTest {
}
}
@Test
void listWithoutQualifierReturnsAnEmptyConfigurationPage() {
for (String reference : List.of(NAME, functionArn(NAME), resolver.getAccountId() + ":function:" + NAME)) {
given().queryParam("List", "ALL").pathParam("function", reference)
.get("/2019-09-30/functions/{function}/provisioned-concurrency")
.then().statusCode(200)
.body("ProvisionedConcurrencyConfigs", equalTo(List.of()))
.body("NextMarker", nullValue());
}
}
@Test
void listMissingFunctionUsesTheFunctionNotFoundError() {
given().queryParam("List", "ALL")
.get("/2019-09-30/functions/pc-absent-function-control/provisioned-concurrency")
.then().statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
void getWithoutQualifierStillRejectsTheRequest() {
given().get("/2019-09-30/functions/" + NAME + "/provisioned-concurrency")
.then().statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
}
private String functionArn(String name) {
return resolver.buildArn("lambda", resolver.getRegion(), "function:" + name);
}
@@ -1,7 +1,9 @@
package io.github.hectorvent.floci.services.lambda;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.ServiceConfigAccess;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
@@ -295,6 +297,94 @@ class ProvisionedConcurrencyPoolTest {
await().atMost(Duration.ofSeconds(5)).until(() -> "READY".equals(get().status()));
}
@Test
void listingReportsCurrentCapacityAndRemovesDeletedConfigurations() throws Exception {
put(1);
Environment environment = launched();
assertEquals(get(), pool.list(REGION, "example", ACCOUNT, null, null).items().getFirst().status());
environment.initialized.complete(null);
ready();
ContainerHandle leased = pool.acquire(version, "live");
assertNotNull(leased);
ProvisionedConcurrencyPool.ListedConfiguration entry =
pool.list(REGION, "example", ACCOUNT, null, null).items().getFirst();
assertEquals(AwsArnUtils.Arn.of("lambda", REGION, ACCOUNT, "function:example:live").toString(),
entry.functionArn());
assertEquals(get(), entry.status());
assertEquals(1, entry.status().allocated());
assertEquals(0, entry.status().available());
assertTrue(pool.release(leased, false));
pool.delete(REGION, "example", "live", ACCOUNT);
assertTrue(pool.list(REGION, "example", ACCOUNT, null, null).items().isEmpty());
}
@Test
void listingKeepsFailedInitializationVisible() throws Exception {
put(1);
launched().initialized.completeExceptionally(new IllegalStateException("initialization failed"));
await().atMost(Duration.ofSeconds(5)).until(() -> "FAILED".equals(get().status()));
assertEquals(get(), pool.list(REGION, "example", ACCOUNT, null, null).items().getFirst().status());
}
@Test
void listingSeparatesAccountsRegionsAndPartitions() throws Exception {
for (String region : List.of(REGION, "cn-north-1")) {
for (String account : List.of(ACCOUNT, "222222222222")) {
function(account, region, "$LATEST");
function(account, region, "1");
alias(account, region, "live", "1", Map.of());
pool.put(region, "example", "live", 1, account);
launched().initialized.complete(null);
}
}
for (String region : List.of(REGION, "cn-north-1")) {
for (String account : List.of(ACCOUNT, "222222222222")) {
List<ProvisionedConcurrencyPool.ListedConfiguration> entries =
pool.list(region, "example", account, null, null).items();
assertEquals(1, entries.size());
assertEquals(AwsArnUtils.Arn.of("lambda", region, account, "function:example:live").toString(),
entries.getFirst().functionArn());
}
}
}
@Test
void listingPagesByQualifierAndRefusesForeignMarkers() throws Exception {
put(1);
launched().initialized.complete(null);
function(ACCOUNT, REGION, "2");
pool.put(REGION, "example", "2", 1, ACCOUNT);
launched().initialized.complete(null);
PaginatedResult<ProvisionedConcurrencyPool.ListedConfiguration> first =
pool.list(REGION, "example", ACCOUNT, "1", null);
assertEquals(1, first.items().size());
assertTrue(first.items().getFirst().functionArn().endsWith(":2"));
assertNotNull(first.nextToken());
pool.delete(REGION, "example", "2", ACCOUNT);
PaginatedResult<ProvisionedConcurrencyPool.ListedConfiguration> last =
pool.list(REGION, "example", ACCOUNT, "1", first.nextToken());
assertEquals(1, last.items().size());
assertTrue(last.items().getFirst().functionArn().endsWith(":live"));
assertNull(last.nextToken());
assertThrows(AwsException.class, () -> pool.list(REGION, "example", ACCOUNT, "1", "fabricated"));
function("222222222222", REGION, "$LATEST");
function(ACCOUNT, "us-west-2", "$LATEST");
functions.save(REGION, LambdaFunctionTestFixtures.function(ACCOUNT, REGION, "other", "$LATEST"));
assertThrows(AwsException.class,
() -> pool.list(REGION, "example", "222222222222", "1", first.nextToken()));
assertThrows(AwsException.class,
() -> pool.list("us-west-2", "example", ACCOUNT, "1", first.nextToken()));
assertThrows(AwsException.class,
() -> pool.list(REGION, "other", ACCOUNT, "1", first.nextToken()));
}
@ParameterizedTest
@ValueSource(strings = {"0", "51", "-1", "one"})
void listingRejectsInvalidPageSizes(String maxItems) {
assertThrows(AwsException.class, () -> pool.list(REGION, "example", ACCOUNT, maxItems, null));
assertEquals(0, launcher.starts.get());
}
@Test
void initializationThenExactQualifierReuseDoesNotInvokeHandler() throws Exception {
assertEquals("IN_PROGRESS", put(1).status());
@@ -1362,16 +1452,19 @@ class ProvisionedConcurrencyPoolTest {
launched().initialized.complete(null);
launched().initialized.complete(null);
ready();
assertEquals(get(), pool.list(REGION, "example", ACCOUNT, null, null).items().getFirst().status());
} else if (restart == 1) {
assertEquals(2, get().requested());
assertEquals("IN_PROGRESS", get().status());
assertEquals(0, get().allocated());
assertEquals(get(), pool.list(REGION, "example", ACCOUNT, null, null).items().getFirst().status());
launched().initialized.complete(null);
launched().initialized.complete(null);
ready();
pool.delete(REGION, "example", "live", ACCOUNT);
} else {
assertThrows(AwsException.class, this::get);
assertTrue(pool.list(REGION, "example", ACCOUNT, null, null).items().isEmpty());
}
} finally {
pool.shutdown();