mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
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:
1 parent
c37e0aaba9
commit
b6d9e4c7a4
10 files changed
+354
-19
No files matched your search
@@ -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;
|
||||
|
||||
+17
-1
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
+31
-4
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user