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

@@ -6,6 +6,8 @@ import software.amazon.awssdk.services.lambda.LambdaClient;
import software.amazon.awssdk.services.lambda.model.*;
import software.amazon.awssdk.services.lambda.model.Runtime;
import java.util.List;
import static org.assertj.core.api.Assertions.*;
@DisplayName("Lambda Function URL Config")
@@ -18,6 +20,8 @@ class LambdaFunctionUrlTest {
@BeforeAll
static void setup() {
Assumptions.assumeFalse(List.of("aws-cn", "aws-us-gov").contains(TestFixtures.partition()),
"Lambda function URLs are not available in the China and GovCloud partitions");
lambda = TestFixtures.lambdaClient();
lambda.createFunction(CreateFunctionRequest.builder()
.functionName(FUNCTION_NAME)
+7 -1
View File
@@ -125,6 +125,11 @@ back to `aws` for a label no partition publishes.
refused outside the commercial partition (`BadRequestException`): GovCloud, EUSC and ISO have no
CloudFront, and China has no edge-optimized API Gateway
([China API Gateway](https://docs.amazonaws.cn/en_us/aws/latest/userguide/api-gateway.html)).
A Lambda function URL is refused in GovCloud and China (`InvalidParameterValueException` on
`CreateFunctionUrlConfig`), where the
[GovCloud](https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-lambda.html) and
[China](https://docs.amazonaws.cn/en_us/aws/latest/userguide/lambda.html) guides list function URLs
as not available.
- **VPC endpoint service names**: interface endpoints (as `DescribeVpcEndpointServices` lists them)
are `com.amazonaws.<region>.<service>` everywhere, except the (region, service) pairs the CDK
lists for China, ISO and EUSC, which reverse the DNS suffix (`cn.com.amazonaws.cn-north-1.lambda`).
@@ -237,7 +242,8 @@ the commercial value or Floci's own base host until sourced:
- the China CloudFront distribution domain suffix (only the API host is published);
- the STS web-identity audience outside the commercial partition;
- the EKS Pod Identity token audience (`pods.eks.amazonaws.com`) outside the commercial partition;
- the Lambda function-URL host outside the commercial partition;
- the Lambda function-URL host in the ISO and EUSC partitions (function URLs are refused in GovCloud
and China, where the partition guides list them as not available);
- whether AWS managed policy documents differ in content in China or GovCloud;
- the API Gateway regional hosted zone per region;
- the availability-zone id prefix of the ISO and EUSC regions: zone ids there keep the whole region
+7
View File
@@ -375,6 +375,13 @@ disabled fails with Lambda's error as the resource status reason.
Function URLs are also reachable directly on `/{proxy:.*}` under the Lambda URL controller, which routes the request into the normal `Invoke` path.
Function URLs are not available in AWS GovCloud (US) or in the China Regions
([GovCloud guide](https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-lambda.html),
[China guide](https://docs.amazonaws.cn/en_us/aws/latest/userguide/lambda.html)), so
`CreateFunctionUrlConfig` is an `InvalidParameterValueException` in those regions, and an
`AWS::Lambda::Url` in a CloudFormation stack there fails with it. See
[AWS Partitions](../configuration/partitions.md).
**Versions:** `CreateFunction` and `UpdateFunctionCode` honour `Publish`, publishing a version
and reporting it in the response's `Version`. The two differ in the ARN they return, matching the
live service: `CreateFunction` keeps the unqualified `FunctionArn` while `UpdateFunctionCode`
@@ -7,6 +7,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
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.AwsPartition;
import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.CustomResourceLiveness;
import io.github.hectorvent.floci.core.common.Digests;
@@ -3050,7 +3052,27 @@ public class LambdaService implements ResourceProvider {
// ──────────────────────────── Function URL Config ────────────────────────────
/** The partitions where AWS documents Lambda function URLs as not available. */
private static final Set<String> FUNCTION_URL_UNAVAILABLE_PARTITIONS = Set.of("aws-us-gov", "aws-cn");
/**
* Function URLs are not available in AWS GovCloud (US) or in the China Regions: "AWS Lambda
* Function URLs is not available"
* (https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-lambda.html) and "Amazon
* Lambda Function URLs is not available in the China Regions"
* (https://docs.amazonaws.cn/en_us/aws/latest/userguide/lambda.html). No source shows AWS's
* message for the refusal, so the wording is Floci's own.
*/
private static void requireFunctionUrlsAvailable(String region) {
AwsPartition partition = AwsPartitions.forRegionOrCommercial(region);
if (FUNCTION_URL_UNAVAILABLE_PARTITIONS.contains(partition.id())) {
throw new AwsException("InvalidParameterValueException",
"Function URLs are not available in partition " + partition.id() + ".", 400);
}
}
public LambdaUrlConfig createFunctionUrlConfig(String region, String functionName, String qualifier, Map<String, Object> request) {
requireFunctionUrlsAvailable(region);
validateFunctionUrlQualifier(qualifier);
LambdaArnUtils.ResolvedFunctionRef ref = resolveWithRegion(region, functionName, qualifier);
functionName = ref.name();
@@ -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());
}
}