fix(lambdaweb): refuse a function name another region already has (#6409)

* fix(lambdaweb): refuse a function name another region already has

AWS keeps web function names unique across the regions of an account.
CreateWebFunction with a name another region has is 409
ConflictException "A function named <name> already exists in the
account. Function names must be unique across all regions in an
account.", at the same point as the same-region conflict.

* fix(lambdaweb): key the function name lock by account

* perf(lambdaweb): find a name in other regions without copying every key
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-24 08:37:19 -04:00
1 parent 3b4589645b
commit 4e0bf080ed
3 files changed
+32 -9

No files matched your search

+1
View File
@@ -40,6 +40,7 @@ The `Lambda Web` service model (apiVersion 2025-03-07, `aws lambda-web` in the A
- **Each revision keeps its own copy of the code**, read at creation from the version the request names or the current one, under the Lambda `code-path`. As on AWS, a later write or delete in the bucket does not change what the revision runs. AWS moves a revision to `Failed` when it later finds its object version gone, which Floci does not do.
- **Execution role:** a role in another account is `403 AccessDeniedException` "Cross-account pass role is not allowed.". A role that does not exist in IAM, or whose trust policy does not let `lambda.amazonaws.com` assume it, is `400 ValidationException` "The execution role <arn> cannot be assumed by lambda.amazonaws.com. Verify its trust policy. If the role was just created, retry in a few seconds.". As on AWS, this check sets no `aws:SourceAccount` or `aws:SourceArn`, so a trust policy that requires either refuses the role. The network connector ARN is checked for shape only.
- **Resource policies** are checked the way AWS checks them before storing: the document grammar, a `lambda:` action, a `Resource` that names the function, a valid principal, and no public `Allow`. A wildcard principal needs a positive condition (`StringEquals`, `StringLike`, `ArnLike`, `Bool`) on a trusted key such as `aws:PrincipalAccount` or `aws:PrincipalArn`, with no wildcard in the account it names. An `IamAuth` endpoint evaluates it on requests, as below.
- **Function names** are unique across the regions of an account, as on AWS. A name that another region already has is `409 ConflictException` "A function named <name> already exists in the account. Function names must be unique across all regions in an account.".
- **ARNs** given as identifiers must name the request's region and the caller's account, as on AWS. A revision or endpoint ARN resolves by its id or name only.
- **Page tokens** are base64 cursors that carry the request and the position of the page, not the UUIDs AWS issues. A token reused with other parameters gets the AWS "does not match the request" error, and any other token the "invalid or has expired" error.
- **Domain names** take the form `<id>.001.lambda-web.<region>.<floci host>` and `<id>.lambda-web.global.<floci host>`, with the host and port of `floci.base-url`. A `PerRegion` endpoint gets one domain per region in `regionalEndpoints`.
@@ -335,19 +335,29 @@ public class LambdaWebService implements Resettable {
}
}
/** Stores a new function under its lock, refusing a name the region already has. */
/**
* Stores a new function under its lock, refusing a name the account already has in any region.
* Creates of one name in every region of the account share a lock, so two regions cannot both take it.
*/
private WebFunction storeNewFunction(String region, String functionName, Map<String, String> tags,
Consumer<WebFunction> populate) {
String accountId = regionResolver.getAccountId();
synchronized (lockFor(region, functionName)) {
if (functions.get(key(region, functionName)).isPresent()) {
throw new AwsException("ConflictException",
"The function " + functionArn(region, accountId, functionName) + " already exists.", 409);
synchronized (locks.computeIfAbsent(accountId + "/" + functionName, k -> new Object())) {
synchronized (lockFor(region, functionName)) {
if (functions.get(key(region, functionName)).isPresent()) {
throw new AwsException("ConflictException",
"The function " + functionArn(region, accountId, functionName) + " already exists.", 409);
}
if (!functions.scan(k -> k.endsWith("/" + functionName)).isEmpty()) {
throw new AwsException("ConflictException", "A function named " + functionName
+ " already exists in the account. Function names must be unique across all regions"
+ " in an account.", 409);
}
WebFunction fn = newFunction(region, accountId, functionName, tags == null ? Map.of() : tags);
populate.accept(fn);
functions.put(key(region, functionName), fn);
return copy(fn, WebFunction.class);
}
WebFunction fn = newFunction(region, accountId, functionName, tags == null ? Map.of() : tags);
populate.accept(fn);
functions.put(key(region, functionName), fn);
return copy(fn, WebFunction.class);
}
}
@@ -571,6 +571,18 @@ class LambdaWebIntegrationTest {
.when().put(BASE + "/web-functions")
.then().statusCode(409)
.body("message", equalTo("The function " + ARN + " already exists."));
given().contentType("application/json")
.header("Authorization", "AWS4-HMAC-SHA256 Credential=test/20260101/us-west-2/lambda/aws4_request")
.body("""
{"functionName": "%s",
"revisionConfig": {"buildConfig": %s, "serviceConfig": {"executionRoleArn": "%s"}},
"endpointConfig": {"endpointName": "dev", "endpointType": "HomeRegion",
"authType": "ApplicationManaged"}}
""".formatted(FN, BUILD.replace("nodejs24.x", "nodejs22.x"), ROLE))
.when().put(BASE + "/web-functions")
.then().statusCode(409)
.body("message", equalTo("A function named " + FN + " already exists in the account. Function names"
+ " must be unique across all regions in an account."));
given().when().get(BASE + "/web-functions/does-not-exist")
.then().statusCode(404)
.body("message", equalTo("The function arn:aws:lambda:us-east-1:000000000000:web-function/does-not-exist"