fix(lambda): refuse function URLs in GovCloud and China (#5615)

The AWS GovCloud (US) User Guide lists "AWS Lambda Function URLs is not
available"
(https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-lambda.html)
and the China guide "Amazon Lambda Function URLs is not available in the
China Regions"
(https://docs.amazonaws.cn/en_us/aws/latest/userguide/lambda.html), but
CreateFunctionUrlConfig created one in every partition, on a host no
source publishes for either of them.

CreateFunctionUrlConfig now refuses a request whose region is in
aws-us-gov or aws-cn with an InvalidParameterValueException, which the
lambda model declares for the operation. No source shows AWS's message,
so the wording is Floci's own, as for the API Gateway EDGE gate. The
AWS::Lambda::Url provisioner creates through the same service method, so
a stack in those partitions fails with that error. Get, Update and Delete
act on an existing config and are unchanged. The ISO and EUSC partitions
are left as they are because no source covers them, and the open
question about the function URL host now names only those two.

The Java compat suite skips LambdaFunctionUrlTest in those two partitions,
so the China partition nightly stays green.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-13 23:58:42 -04:00
1 parent d3999ad416
commit 255162654f
6 files changed
+167 -1

No files matched your search

@@ -148,6 +148,39 @@ class PartitionRegionGatesIntegrationTest {
switchRestApiToEdge("us-east-1", commercialId).then().statusCode(200);
}
private Response createFunctionUrl(String region) {
String name = "url-gate-" + Long.toString(System.nanoTime(), 36);
// By name, before the create: a failure reading the response then leaves nothing behind.
cleanup.register(() -> given()
.header("Authorization", PartitionMatrix.sigV4Auth(region, "lambda"))
.when().delete("/2015-03-31/functions/" + name));
given()
.header("Authorization", PartitionMatrix.sigV4Auth(region, "lambda"))
.contentType("application/json")
.body("{\"FunctionName\":\"" + name + "\",\"Runtime\":\"nodejs20.x\",\"Handler\":\"index.handler\","
+ "\"Role\":\"arn:" + AwsRegions.partitionFor(region) + ":iam::000000000000:role/lambda-role\"}")
.when().post("/2015-03-31/functions")
.then().statusCode(201);
return given()
.header("Authorization", PartitionMatrix.sigV4Auth(region, "lambda"))
.contentType("application/json")
.body("{\"AuthType\":\"NONE\"}")
.when().post("/2021-10-31/functions/" + name + "/url");
}
/** GovCloud and China have Lambda but no function URLs, so creating one is refused there. */
@Test
void functionUrlsAreRejectedInGovCloudAndChina() {
for (String region : List.of("us-gov-west-1", "cn-north-1")) {
createFunctionUrl(region).then().statusCode(400)
.header("x-amzn-ErrorType", containsString("InvalidParameterValueException"))
.body(containsString("not available in partition " + AwsRegions.partitionFor(region)));
}
createFunctionUrl("us-east-1").then().statusCode(201)
.body("FunctionUrl", containsString(".lambda-url.us-east-1."));
}
@Test
void cloudFrontScopeLivesInThePartitionsImplicitGlobalRegion() {
String name = "cn-" + Long.toString(System.nanoTime(), 36);
@@ -0,0 +1,94 @@
package io.github.hectorvent.floci.services.lambda;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.lambda.model.LambdaFunction;
import io.github.hectorvent.floci.services.lambda.model.LambdaUrlConfig;
import io.github.hectorvent.floci.services.lambda.zip.CodeStore;
import io.github.hectorvent.floci.services.lambda.zip.ZipExtractor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Lambda function URLs are not available in AWS GovCloud (US) or in the China Regions, so one
* cannot be created there, while the commercial partition and the partitions no source covers
* are unchanged.
*/
class LambdaFunctionUrlPartitionTest {
private static final String ACCOUNT = "000000000000";
private static final String FUNCTION_NAME = "url-gate-fn";
private LambdaService service;
@BeforeEach
void setUp() {
StorageFactory storageFactory = mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any()))
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory(ACCOUNT));
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.effectiveBaseUrl()).thenReturn("http://localhost:4566");
service = new LambdaService(new LambdaFunctionStore(new InMemoryStorage<String, LambdaFunction>()),
new WarmPool(), new CodeStore(Path.of("target/test-data/lambda-code")), new ZipExtractor(),
config, new RegionResolver("us-east-1", ACCOUNT), storageFactory);
}
private void createFunction(String region) {
Map<String, Object> request = new HashMap<>();
request.put("FunctionName", FUNCTION_NAME);
request.put("Runtime", "nodejs20.x");
request.put("Role", "arn:" + AwsRegions.partitionFor(region) + ":iam::" + ACCOUNT + ":role/test-role");
request.put("Handler", "index.handler");
service.createFunction(region, request);
}
@ParameterizedTest
@ValueSource(strings = {"us-gov-west-1", "us-gov-east-1", "cn-north-1", "cn-northwest-1"})
void aFunctionUrlIsRefusedInGovCloudAndChina(String region) {
createFunction(region);
AwsException error = assertThrows(AwsException.class,
() -> service.createFunctionUrlConfig(region, FUNCTION_NAME, null, Map.of("AuthType", "NONE")));
assertEquals("InvalidParameterValueException", error.getErrorCode());
assertEquals(400, error.getHttpStatus());
assertThat(error.getMessage(),
containsString("not available in partition " + AwsRegions.partitionFor(region)));
assertNull(service.getFunction(region, FUNCTION_NAME).getUrlConfig());
}
@ParameterizedTest
@ValueSource(strings = {"us-east-1", "eu-west-1", "us-iso-east-1", "eusc-de-east-1"})
void aFunctionUrlIsAcceptedWhereNoSourceRulesItOut(String region) {
createFunction(region);
LambdaUrlConfig created =
service.createFunctionUrlConfig(region, FUNCTION_NAME, null, Map.of("AuthType", "NONE"));
assertEquals("NONE", created.getAuthType());
assertThat(created.getFunctionUrl(), containsString(".lambda-url." + region + "."));
assertEquals(created.getFunctionUrl(),
service.getFunctionUrlConfig(region, FUNCTION_NAME, null).getFunctionUrl());
}
}