Skip to content

armgit / floci

Public Imported from GitHub
0

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

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

Andre Kuraitb6d9e4c7a49f
diff --git a/compatibility-tests/sdk-test-python/tests/test_lambda_provisioned_list.py b/compatibility-tests/sdk-test-python/tests/test_lambda_provisioned_list.py
new file mode 100644
index 0000000000..ffb57b63e5
--- /dev/null
+++ b/compatibility-tests/sdk-test-python/tests/test_lambda_provisioned_list.py
@@ -0,0 +1,86 @@
+"""Provisioned concurrency lists use the AWS SDK's unqualified, paginated request."""
+
+import io
+import time
+import zipfile
+
+import pytest
+from botocore.exceptions import ClientError
+
+
+def provisioned_list_function(lambda_client, minimal_lambda_zip, unique_name):
+ created = lambda_client.create_function(
+ FunctionName=unique_name, Runtime="nodejs22.x", Handler="index.handler",
+ Role="arn:aws:iam::000000000000:role/lambda-role",
+ Code={"ZipFile": minimal_lambda_zip},
+ )
+ try:
+ yield unique_name, created["FunctionArn"]
+ finally:
+ lambda_client.delete_function(FunctionName=unique_name)
+
+
[email protected]("form", ["name", "arn", "partial"])
+def test_empty_list_uses_the_unqualified_function(lambda_client, provisioned_list_function, form):
+ name, arn = provisioned_list_function
+ reference = {"name": name, "arn": arn, "partial": arn.split(":", 4)[4]}[form]
+ response = lambda_client.list_provisioned_concurrency_configs(FunctionName=reference)
+ assert response["ProvisionedConcurrencyConfigs"] == []
+ assert "NextMarker" not in response
+
+
+def test_list_missing_function_returns_resource_not_found(lambda_client, unique_name):
+ with pytest.raises(ClientError) as error:
+ lambda_client.list_provisioned_concurrency_configs(FunctionName=unique_name)
+ assert error.value.response["Error"]["Code"] == "ResourceNotFoundException"
+ assert error.value.response["ResponseMetadata"]["HTTPStatusCode"] == 404
+
+
+def test_list_preserves_qualifiers_status_pagination_and_deletion(lambda_client, provisioned_list_function):
+ name, arn = provisioned_list_function
+ first = lambda_client.publish_version(FunctionName=name)["Version"]
+ lambda_client.create_alias(FunctionName=name, Name="live", FunctionVersion=first)
+ code = io.BytesIO()
+ with zipfile.ZipFile(code, "w") as archive:
+ archive.writestr("index.js", "exports.handler = async () => 'second version';")
+ second = lambda_client.update_function_code(
+ FunctionName=name, ZipFile=code.getvalue(), Publish=True
+ )["Version"]
+ assert second != first
+ for qualifier in ("live", second):
+ lambda_client.put_provisioned_concurrency_config(
+ FunctionName=name, Qualifier=qualifier, ProvisionedConcurrentExecutions=1
+ )
+ deadline = time.monotonic() + 120
+ while True:
+ statuses = {
+ qualifier: lambda_client.get_provisioned_concurrency_config(
+ FunctionName=name, Qualifier=qualifier
+ )
+ for qualifier in ("live", second)
+ }
+ assert all(value["Status"] != "FAILED" for value in statuses.values()), statuses
+ if all(value["Status"] == "READY" for value in statuses.values()):
+ break
+ assert time.monotonic() < deadline, statuses
+ time.sleep(0.2)
+ pages = list(lambda_client.get_paginator("list_provisioned_concurrency_configs").paginate(
+ FunctionName=name, PaginationConfig={"PageSize": 1}
+ ))
+ assert len(pages) == 2
+ assert "NextMarker" in pages[0] and "NextMarker" not in pages[1]
+ entries = [entry for page in pages for entry in page["ProvisionedConcurrencyConfigs"]]
+ assert {entry["FunctionArn"] for entry in entries} == {arn + ":live", arn + ":" + second}
+ for entry in entries:
+ qualifier = entry["FunctionArn"].rsplit(":", 1)[1]
+ for field in ("Status", "RequestedProvisionedConcurrentExecutions",
+ "AllocatedProvisionedConcurrentExecutions", "AvailableProvisionedConcurrentExecutions",
+ "LastModified"):
+ assert entry[field] == statuses[qualifier][field]
+ assert entry["Status"] == "READY"
+ assert entry["AllocatedProvisionedConcurrentExecutions"] == 1
+ assert entry["AvailableProvisionedConcurrentExecutions"] == 1
+ lambda_client.delete_provisioned_concurrency_config(FunctionName=name, Qualifier="live")
+ remaining = lambda_client.list_provisioned_concurrency_configs(FunctionName=name)["ProvisionedConcurrencyConfigs"]
+ assert [entry["FunctionArn"] for entry in remaining] == [arn + ":" + second]
diff --git a/docs/services/lambda.md b/docs/services/lambda.md
index beca53af94..06f5c905de 100644
--- a/docs/services/lambda.md
+++ b/docs/services/lambda.md
@@ -51,6 +51,7 @@ Floci Lambda runs your function code locally inside real Docker containers - clo
| `DeleteFunctionConcurrency` | Clear reserved concurrent executions |
| `PutProvisionedConcurrencyConfig` | Initialize Docker environments for a published version or simple alias |
| `GetProvisionedConcurrencyConfig` | Read the allocation's actual initialization status and capacity |
+| `ListProvisionedConcurrencyConfigs` | List configured versions and aliases with their current capacity |
| `DeleteProvisionedConcurrencyConfig` | Remove an allocation and stop its environments |
| `GetAccountSettings` | Account limits plus usage derived from the caller's stored functions |
| `PutFunctionEventInvokeConfig` | Set the asynchronous invocation settings of a function, version or alias (retries, event age, destinations) |
@@ -500,6 +501,12 @@ with a required `Qualifier` query parameter. Put accepts a positive integer
function without a configuration returns `ProvisionedConcurrencyConfigNotFoundException`
from Get.
+List uses the same route with `List=ALL` and no qualifier. It returns the function's
+configured versions and aliases, their qualified `FunctionArn` and current allocation status.
+An existing function without configurations returns an empty list. `MaxItems` accepts 1
+through 50; `NextMarker` resumes with `Marker`. Markers are scoped to the function, account
+and region. Name, full ARN and partial ARN references use the same configuration inventory.
+
An alias and its resolved published version cannot both have configurations. Different
aliases of the same provisioned version also conflict; other versions remain independent.
`LastModified` uses Lambda's UTC `+0000` form.
@@ -571,7 +578,6 @@ For a longer drain, explicitly stop with the larger timeout and then start Floci
These AWS Lambda operations have no handler in Floci. Calls will return `404` or an error:
- Layer permissions (`AddLayerVersionPermission`, `RemoveLayerVersionPermission`, `GetLayerVersionPolicy`)
-- Listing provisioned concurrency (`ListProvisionedConcurrencyConfigs`)
- `InvokeWithResponseStream`
- Code signing enforcement. A configuration is created, read, updated, deleted and listed, and
nothing verifies a signature against it, so it never gates a deployment. Attaching one to a
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java
index 8c8840dd62..b58af74e8c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtils.java
@@ -135,6 +135,19 @@ public final class LambdaArnUtils {
return new ResolvedFunctionRef(ref.name(), effective, ref.region(), ref.account());
}
+ /** Resolves the qualifier and requires a full ARN to name the request region. */
+ public static ResolvedFunctionRef resolveWithRegion(String region, String input, String queryQualifier) {
+ ResolvedFunctionRef ref = resolveWithQualifier(input, queryQualifier);
+ enforceRegion(region, ref);
+ return ref;
+ }
+
+ static void enforceRegion(String region, ResolvedFunctionRef ref) {
+ if (ref.region() != null && !ref.region().equals(region)) {
+ throw invalid("Region '" + ref.region() + "' in ARN does not match request region '" + region + "'");
+ }
+ }
+
private static ResolvedFunctionRef parseFullArn(String input) {
// arn:aws:lambda:REGION:ACCT:function:NAME[:QUALIFIER]
AwsArnUtils.Arn base;
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyController.java
index 9bd46141e1..f8241c6702 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyController.java
@@ -2,8 +2,10 @@ package io.github.hectorvent.floci.services.lambda;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RegionResolver;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
@@ -68,7 +70,21 @@ public class LambdaProvisionedConcurrencyController {
@GET
public Response get(@Context HttpHeaders headers, @PathParam("functionName") String name,
- @QueryParam("Qualifier") String qualifier) {
+ @QueryParam("Qualifier") String qualifier, @QueryParam("List") String list,
+ @QueryParam("MaxItems") String maxItems, @QueryParam("Marker") String marker) {
+ if ("ALL".equals(list)) {
+ PaginatedResult<ProvisionedConcurrencyPool.ListedConfiguration> page = pool.list(
+ regions.resolveRegion(headers), name, regions.getAccountId(), maxItems, marker);
+ ObjectNode result = mapper.createObjectNode();
+ ArrayNode configurations = result.putArray("ProvisionedConcurrencyConfigs");
+ for (ProvisionedConcurrencyPool.ListedConfiguration entry : page.items()) {
+ configurations.add(wire(entry.status()).put("FunctionArn", entry.functionArn()));
+ }
+ if (page.nextToken() != null) {
+ result.put("NextMarker", page.nextToken());
+ }
+ return Response.ok(result).build();
+ }
return Response.ok(wire(pool.get(regions.resolveRegion(headers), name, qualifier,
regions.getAccountId()))).build();
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
index b9c75049f7..65410ee006 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
@@ -656,7 +656,7 @@ public class LambdaService implements ResourceProvider {
*/
public LambdaFunction getFunction(String region, String functionName, String qualifier) {
LambdaArnUtils.ResolvedFunctionRef ref = LambdaArnUtils.resolve(functionName);
- enforceRegion(region, ref);
+ LambdaArnUtils.enforceRegion(region, ref);
String effective = resolveQualifier(ref.qualifier(), qualifier);
if (effective == null) {
return getFunction(region, functionName);
@@ -691,7 +691,7 @@ public class LambdaService implements ResourceProvider {
*/
String canonicalFunctionName(String region, String functionName) {
LambdaArnUtils.ResolvedFunctionRef ref = LambdaArnUtils.resolve(functionName);
- enforceRegion(region, ref);
+ LambdaArnUtils.enforceRegion(region, ref);
return ref.name();
}
@@ -701,16 +701,7 @@ public class LambdaService implements ResourceProvider {
* value, enforcing region match when the input is a full ARN.
*/
LambdaArnUtils.ResolvedFunctionRef resolveWithRegion(String region, String functionName, String queryQualifier) {
- LambdaArnUtils.ResolvedFunctionRef ref = LambdaArnUtils.resolveWithQualifier(functionName, queryQualifier);
- enforceRegion(region, ref);
- return ref;
- }
-
- private void enforceRegion(String region, LambdaArnUtils.ResolvedFunctionRef ref) {
- if (ref.region() != null && !ref.region().equals(region)) {
- throw new AwsException("InvalidParameterValueException",
- "Region '" + ref.region() + "' in ARN does not match request region '" + region + "'", 400);
- }
+ return LambdaArnUtils.resolveWithRegion(region, functionName, queryQualifier);
}
private record ResolvedFunctionTarget(String functionArn, String functionName) {}
@@ -1448,7 +1439,7 @@ public class LambdaService implements ResourceProvider {
}
eventSourceArn = null;
- enforceRegion(region, fnRef);
+ LambdaArnUtils.enforceRegion(region, fnRef);
resolvedRegion = region;
Object rawSource = request.get("SelfManagedEventSource");
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPool.java b/src/main/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPool.java
index 984047a58d..8e9a053308 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPool.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPool.java
@@ -5,7 +5,10 @@ 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.ContainerTeardowns;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.common.SignedMarkers;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
@@ -59,6 +62,7 @@ public class ProvisionedConcurrencyPool implements Resettable {
private final boolean ephemeral;
private final long drainTimeoutNanos;
private final Map<String, Allocation> allocations = new HashMap<>();
+ private final SignedMarkers listMarkers = new SignedMarkers();
private final Map<ContainerHandle, Allocation> leases = new HashMap<>();
private final Map<ContainerHandle, Configuration> owned = new HashMap<>();
private final Set<Allocation> launchingAllocations = new HashSet<>();
@@ -83,6 +87,8 @@ public class ProvisionedConcurrencyPool implements Resettable {
public record Status(int requested, int allocated, int available, String status,
String reason, String lastModified) {}
+ public record ListedConfiguration(String functionArn, Status status) {}
+
private static final class Allocation {
final Configuration configuration;
final Set<ContainerHandle> handles = new HashSet<>();
@@ -235,6 +241,30 @@ public class ProvisionedConcurrencyPool implements Resettable {
}
}
+ public PaginatedResult<ListedConfiguration> list(String region, String name, String account,
+ String maxItems, String marker) {
+ List<String> errors = new ArrayList<>();
+ Integer limit = LambdaPagination.parseMaxItems(maxItems, 50, errors);
+ if (!errors.isEmpty()) {
+ throw SmithyValidationErrors.validationException(errors);
+ }
+ LambdaArnUtils.ResolvedFunctionRef ref = LambdaArnUtils.resolveWithRegion(region, name, null);
+ String owner = ref.account() == null ? account : ref.account();
+ String functionArn = AwsArnUtils.Arn.of("lambda", region, owner, "function:" + ref.name()).toString();
+ functions.getForAccount(owner, region, ref.name())
+ .orElseThrow(() -> missing("Function not found: " + functionArn));
+ reconcile();
+ List<ListedConfiguration> entries;
+ synchronized (lock) {
+ entries = allocations.values().stream()
+ .filter(allocation -> functionArn.equals(allocation.configuration.functionArn()))
+ .map(allocation -> new ListedConfiguration(allocation.configuration.key(), status(allocation)))
+ .toList();
+ }
+ return LambdaPagination.paginate(entries, ListedConfiguration::functionArn, limit, 50, marker,
+ listMarkers, functionArn + "\n");
+ }
+
public void delete(String region, String name, String qualifier, String account) {
Target target = resolveTarget(region, name, qualifier, account);
synchronized (functions.lockForConcurrencyOp(target.functionArn())) {
@@ -729,10 +759,7 @@ public class ProvisionedConcurrencyPool implements Resettable {
if ("$LATEST".equals(qualifier)) {
throw invalid("The function resource provided must be an alias or a published version.");
}
- LambdaArnUtils.ResolvedFunctionRef ref = LambdaArnUtils.resolveWithQualifier(name, qualifier);
- if (ref.region() != null && !region.equals(ref.region())) {
- throw invalid("Function ARN region must match the request region");
- }
+ LambdaArnUtils.ResolvedFunctionRef ref = LambdaArnUtils.resolveWithRegion(region, name, qualifier);
account = ref.account() != null ? ref.account() : account;
boolean publishedVersion = qualifier.matches("[0-9]+");
String qualifiedArn = AwsArnUtils.Arn.of("lambda", region, account,
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtilsTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtilsTest.java
index 5091d0b720..9c91cfa158 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtilsTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaArnUtilsTest.java
@@ -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
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyIntegrationTest.java
index 0519d65235..ca4a279a69 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyIntegrationTest.java
@@ -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()))
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyNotFoundIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyNotFoundIntegrationTest.java
index 8fe385ef2d..89b8e3d05e 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyNotFoundIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaProvisionedConcurrencyNotFoundIntegrationTest.java
@@ -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);
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPoolTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPoolTest.java
index 8afa6d1bc8..b8340615ac 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPoolTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/ProvisionedConcurrencyPoolTest.java
@@ -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();