mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(lambda): list function URL configurations (#8410)
ListFunctionUrlConfigs answers GET /2021-10-31/functions/{FunctionName}/urls,
which returned 404 before. It returns the stored URL configurations of the
unpublished function and its aliases, with signed markers scoped to the
function, account and Region, and refuses GovCloud and China like the other
URL operations. MaxItems and the marker go through LambdaPagination, and a
missing or foreign function answers Function not found.
The URL, S3 code and permission tests share one Node.js ZIP builder,
LambdaCodeFixtures.nodeJsZip.
Signed-off-by: Jackson Price <jxnprice@amazon.com>
Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
704f895982
commit
e7767b8bac
9 files changed
+498
-35
No files matched your search
+10
-2
@@ -43,6 +43,7 @@ Floci Lambda runs your function code locally inside real Docker containers - clo
|
||||
| `ListCodeSigningConfigs` | List the configurations in the region |
|
||||
| `CreateFunctionUrlConfig` | Provision a function URL |
|
||||
| `GetFunctionUrlConfig` | Read function URL config |
|
||||
| `ListFunctionUrlConfigs` | List a function's URL configurations across its unpublished version and aliases, with marker pagination |
|
||||
| `UpdateFunctionUrlConfig` | Update function URL config |
|
||||
| `DeleteFunctionUrlConfig` | Delete function URL config |
|
||||
| `ListTags` | List tags on a function or event source mapping |
|
||||
@@ -463,13 +464,20 @@ 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.
|
||||
|
||||
`ListFunctionUrlConfigs` lists the unpublished function's URL and its alias URLs.
|
||||
It accepts `MaxItems` from 1 through 50, defaulting to 50, and resumes with `Marker`.
|
||||
Pagination uses Lambda's shared validation: out-of-range integers return
|
||||
`ValidationException`, non-integers return `SerializationException`, and an invalid
|
||||
marker returns `InvalidParameterValueException` with `Invalid pagination key.`.
|
||||
Missing or inaccessible function references return `ResourceNotFoundException`.
|
||||
|
||||
A function URL with `InvokeMode: RESPONSE_STREAM` streams the response: each chunk the handler writes reaches the caller as it is written. When the handler uses `awslambda.HttpResponseStream.from`, the status code, headers and cookies come from its prelude. Otherwise the response is a `200` with the content type the handler set, `application/octet-stream` by default. A function that fails before its stream starts, in its init or by timing out, answers `502`. An error the handler throws ends the body where it stopped, an empty `200` if it wrote nothing: the runtime reports it in HTTP trailers, which Floci's runtime API does not read. A handler that does not stream is answered as with `BUFFERED`.
|
||||
|
||||
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
|
||||
`CreateFunctionUrlConfig` and `ListFunctionUrlConfigs` return `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
|
||||
|
||||
@@ -116,6 +116,7 @@ public class LambdaService implements ResourceProvider {
|
||||
private static final int MAX_TOPICS = 1;
|
||||
private static final int MAX_SOURCE_ACCESS_CONFIGURATIONS = 23;
|
||||
private static final int LIST_FUNCTIONS_PAGE_SIZE = 50;
|
||||
private static final int FUNCTION_URL_CONFIGS_PAGE_SIZE = 50;
|
||||
private static final int MAX_LIST_FUNCTIONS_ITEMS = 10_000;
|
||||
private static final int MAX_ENVIRONMENT_BYTES = 4096;
|
||||
private static final int MAX_ENVIRONMENT_DIAGNOSTIC_BYTES = 5120;
|
||||
@@ -221,6 +222,7 @@ public class LambdaService implements ResourceProvider {
|
||||
private final ConcurrentHashMap<String, Object> versionCounterLocks = new ConcurrentHashMap<>();
|
||||
private final SignedMarkers listFunctionMarkers = new SignedMarkers();
|
||||
private final SignedMarkers codeSigningFunctionMarkers = new SignedMarkers();
|
||||
private final SignedMarkers functionUrlMarkers = new SignedMarkers();
|
||||
|
||||
/**
|
||||
* Package-private constructor for testing without CDI. Config defaults
|
||||
@@ -3537,6 +3539,45 @@ public class LambdaService implements ResourceProvider {
|
||||
return urlConfig;
|
||||
}
|
||||
|
||||
public PaginatedResult<LambdaUrlConfig> listFunctionUrlConfigs(
|
||||
String region, String functionName, String maxItems, String marker) {
|
||||
requireFunctionUrlsAvailable(region);
|
||||
List<String> errors = new ArrayList<>();
|
||||
Integer requested = LambdaPagination.parseMaxItems(maxItems, FUNCTION_URL_CONFIGS_PAGE_SIZE, errors);
|
||||
if (!errors.isEmpty()) {
|
||||
throw SmithyValidationErrors.validationException(errors);
|
||||
}
|
||||
|
||||
LambdaArnUtils.ResolvedFunctionRef ref = resolveWithRegion(region, functionName, null);
|
||||
validateFunctionUrlQualifier(ref.qualifier());
|
||||
if (AwsArnUtils.looksLikeArn(functionName)
|
||||
&& AwsArnUtils.isForeignPartition(AwsArnUtils.parse(functionName),
|
||||
regionResolver.partitionForRegion(region))) {
|
||||
throw new AwsException("ResourceNotFoundException", "Function not found: " + functionName, 404);
|
||||
}
|
||||
String accountId = regionResolver.getAccountId();
|
||||
if (ref.account() != null && !accountId.equals(ref.account())) {
|
||||
throw new AwsException("ResourceNotFoundException", "Function not found: " + functionName, 404);
|
||||
}
|
||||
LambdaFunction function = functionStore.get(region, ref.name())
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Function not found: " + functionName, 404));
|
||||
List<LambdaUrlConfig> urls = new ArrayList<>();
|
||||
if (function.getUrlConfig() != null) {
|
||||
urls.add(function.getUrlConfig());
|
||||
}
|
||||
if (aliasStore != null) {
|
||||
for (LambdaAlias alias : aliasStore.list(region, function.getFunctionName())) {
|
||||
if (alias.getUrlConfig() != null) {
|
||||
urls.add(alias.getUrlConfig());
|
||||
}
|
||||
}
|
||||
}
|
||||
String scope = accountId + "\n" + region + "\n" + function.getFunctionName() + "\n";
|
||||
return LambdaPagination.paginate(urls, LambdaUrlConfig::getFunctionArn, requested,
|
||||
FUNCTION_URL_CONFIGS_PAGE_SIZE, marker, functionUrlMarkers, scope);
|
||||
}
|
||||
|
||||
public LambdaUrlConfig getFunctionUrlConfig(String region, String functionName, String qualifier) {
|
||||
validateFunctionUrlQualifier(qualifier);
|
||||
return lookupFunctionUrlConfig(region, functionName, qualifier);
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.floci.aws.services.lambda;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.services.lambda.model.LambdaUrlConfig;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -18,14 +19,16 @@ import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* AWS Lambda Function URL configuration API.
|
||||
*/
|
||||
@Path("/2021-10-31/functions/{FunctionName}/url")
|
||||
@Path("/2021-10-31/functions/{FunctionName}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class LambdaUrlController {
|
||||
@@ -44,6 +47,7 @@ public class LambdaUrlController {
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/url")
|
||||
public Response createFunctionUrlConfig(@Context HttpHeaders headers,
|
||||
@PathParam("FunctionName") String functionName,
|
||||
@QueryParam("Qualifier") String qualifier,
|
||||
@@ -63,6 +67,7 @@ public class LambdaUrlController {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/url")
|
||||
public Response getFunctionUrlConfig(@Context HttpHeaders headers,
|
||||
@PathParam("FunctionName") String functionName,
|
||||
@QueryParam("Qualifier") String qualifier) {
|
||||
@@ -72,6 +77,7 @@ public class LambdaUrlController {
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/url")
|
||||
public Response updateFunctionUrlConfig(@Context HttpHeaders headers,
|
||||
@PathParam("FunctionName") String functionName,
|
||||
@QueryParam("Qualifier") String qualifier,
|
||||
@@ -91,6 +97,7 @@ public class LambdaUrlController {
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/url")
|
||||
public Response deleteFunctionUrlConfig(@Context HttpHeaders headers,
|
||||
@PathParam("FunctionName") String functionName,
|
||||
@QueryParam("Qualifier") String qualifier) {
|
||||
@@ -98,4 +105,22 @@ public class LambdaUrlController {
|
||||
lambdaService.deleteFunctionUrlConfig(region, functionName, qualifier);
|
||||
return Response.noContent().build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/urls")
|
||||
public Response listFunctionUrlConfigs(@Context HttpHeaders headers,
|
||||
@PathParam("FunctionName") String functionName,
|
||||
@Context UriInfo uriInfo) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
String maxItems = uriInfo.getQueryParameters().getFirst("MaxItems");
|
||||
String marker = uriInfo.getQueryParameters().getFirst("Marker");
|
||||
PaginatedResult<LambdaUrlConfig> page =
|
||||
lambdaService.listFunctionUrlConfigs(region, functionName, maxItems, marker);
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("FunctionUrlConfigs", page.items());
|
||||
if (page.nextToken() != null) {
|
||||
response.put("NextMarker", page.nextToken());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.floci.aws.services.lambda;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
final class LambdaCodeFixtures {
|
||||
|
||||
private LambdaCodeFixtures() {
|
||||
}
|
||||
|
||||
static byte[] nodeJsZip(String handlerSource) throws IOException {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zip = new ZipOutputStream(bytes)) {
|
||||
zip.putNextEntry(new ZipEntry("index.js"));
|
||||
zip.write(handlerSource.getBytes(StandardCharsets.UTF_8));
|
||||
zip.closeEntry();
|
||||
}
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.floci.aws.services.lambda;
|
||||
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsRegions;
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import software.amazon.awssdk.core.SdkBytes;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.lambda.LambdaClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
final class LambdaFunctionUrlFixtures {
|
||||
|
||||
private LambdaFunctionUrlFixtures() {
|
||||
}
|
||||
|
||||
static String createFunction(LambdaClient client, String name, String account, Region region,
|
||||
URI endpoint, PartitionCleanup cleanup) throws IOException {
|
||||
byte[] archive = LambdaCodeFixtures.nodeJsZip(
|
||||
"exports.handler = async () => ({statusCode: 200, body: 'ok'});");
|
||||
String role = AwsArnUtils.Arn.global(AwsRegions.partitionFor(region.id()),
|
||||
"iam", account, "role/url-list").toString();
|
||||
String arn = client.createFunction(request -> request.functionName(name)
|
||||
.runtime("nodejs22.x").handler("index.handler").role(role)
|
||||
.code(code -> code.zipFile(SdkBytes.fromByteArray(archive)))).functionArn();
|
||||
cleanup.register(() -> {
|
||||
try (LambdaClient owner = AwsTestClients.create(LambdaClient.builder(), account, region, endpoint)) {
|
||||
owner.deleteFunction(request -> request.functionName(name));
|
||||
}
|
||||
});
|
||||
client.publishVersion(request -> request.functionName(name));
|
||||
return arn;
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package io.floci.aws.services.lambda;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.floci.aws.testing.EnforcementFixtures;
|
||||
import io.floci.aws.testing.EnforcementFixtures.UserCredentials;
|
||||
import io.floci.aws.testing.IamEnforcementProfile;
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.lambda.LambdaClient;
|
||||
import software.amazon.awssdk.services.lambda.model.FunctionUrlAuthType;
|
||||
import software.amazon.awssdk.services.lambda.model.LambdaException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.floci.aws.testing.EnforcementFixtures.auth;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(IamEnforcementProfile.class)
|
||||
class LambdaFunctionUrlListIamIntegrationTest {
|
||||
|
||||
private static final String ACCOUNT = "741681410025";
|
||||
|
||||
@TestHTTPResource("/")
|
||||
URI endpoint;
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"name", "arn", "partial"})
|
||||
void listingRequiresPermissionOnTheNamedFunction(String form) throws Exception {
|
||||
Region region = Region.US_EAST_1;
|
||||
String name = "url-list-iam-" + UUID.randomUUID();
|
||||
try (LambdaClient owner = AwsTestClients.create(LambdaClient.builder(), ACCOUNT, region, endpoint)) {
|
||||
String arn = LambdaFunctionUrlFixtures.createFunction(owner, name, ACCOUNT, region, endpoint, cleanup);
|
||||
owner.createFunctionUrlConfig(request -> request.functionName(name).authType(FunctionUrlAuthType.AWS_IAM));
|
||||
String selector = switch (form) {
|
||||
case "arn" -> arn;
|
||||
case "partial" -> ACCOUNT + ":function:" + name;
|
||||
default -> name;
|
||||
};
|
||||
String authorization = auth(ACCOUNT, region.id(), "iam");
|
||||
String user = "url-list-reader-" + UUID.randomUUID();
|
||||
UserCredentials credentials = EnforcementFixtures.createUser(cleanup, endpoint.getPort(), authorization, user);
|
||||
try (LambdaClient reader = AwsTestClients.create(LambdaClient.builder(),
|
||||
credentials.accessKeyId(), credentials.secretAccessKey(), region, endpoint)) {
|
||||
policy(authorization, user, "Allow", arn + "-other");
|
||||
denied(reader, selector);
|
||||
policy(authorization, user, "Deny", arn);
|
||||
denied(reader, selector);
|
||||
policy(authorization, user, "Allow", arn);
|
||||
assertEquals(List.of(arn), reader.listFunctionUrlConfigs(request -> request.functionName(selector))
|
||||
.functionUrlConfigs().stream().map(config -> config.functionArn()).toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void policy(String authorization, String user, String effect, String resource) {
|
||||
EnforcementFixtures.putUserPolicy(endpoint.getPort(), authorization, user, "url-list",
|
||||
"""
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": "lambda:ListFunctionUrlConfigs",
|
||||
"Resource": "%s"
|
||||
},
|
||||
{
|
||||
"Effect": "%s",
|
||||
"Action": "lambda:ListFunctionUrlConfigs",
|
||||
"Resource": "%s"
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted("Deny".equals(effect) ? "*" : resource, effect, resource));
|
||||
}
|
||||
|
||||
private static void denied(LambdaClient client, String name) {
|
||||
LambdaException error = assertThrows(LambdaException.class, () -> client.listFunctionUrlConfigs(request ->
|
||||
request.functionName(name)));
|
||||
assertEquals(403, error.statusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
package io.floci.aws.services.lambda;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.lambda.LambdaClient;
|
||||
import software.amazon.awssdk.services.lambda.model.FunctionUrlAuthType;
|
||||
import software.amazon.awssdk.services.lambda.model.FunctionUrlConfig;
|
||||
import software.amazon.awssdk.services.lambda.model.InvalidParameterValueException;
|
||||
import software.amazon.awssdk.services.lambda.model.LambdaException;
|
||||
import software.amazon.awssdk.services.lambda.model.ListFunctionUrlConfigsResponse;
|
||||
import software.amazon.awssdk.services.lambda.model.ResourceNotFoundException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
class LambdaFunctionUrlListIntegrationTest {
|
||||
|
||||
private static final String ACCOUNT = "741681410001";
|
||||
private static final String REGION = "eu-west-2";
|
||||
private static final String AUTH = "AWS4-HMAC-SHA256 Credential=" + ACCOUNT
|
||||
+ "/20261112/" + REGION + "/lambda/aws4_request";
|
||||
|
||||
@TestHTTPResource("/")
|
||||
URI endpoint;
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
private LambdaClient client;
|
||||
private String functionName;
|
||||
private String functionArn;
|
||||
|
||||
@BeforeEach
|
||||
void createFunction() throws IOException {
|
||||
client = AwsTestClients.create(LambdaClient.builder(), ACCOUNT, Region.of(REGION), endpoint);
|
||||
functionName = "url-list-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
functionArn = createFunction(client, functionName, ACCOUNT, Region.of(REGION));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyListAndMissingFunctionHaveDifferentResponses() {
|
||||
ListFunctionUrlConfigsResponse empty = client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName));
|
||||
assertTrue(empty.functionUrlConfigs().isEmpty());
|
||||
assertNull(empty.nextMarker());
|
||||
ResourceNotFoundException missing = assertThrows(ResourceNotFoundException.class,
|
||||
() -> client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName + "-missing")));
|
||||
assertEquals(404, missing.statusCode());
|
||||
assertEquals("Function not found: " + functionName + "-missing", missing.awsErrorDetails().errorMessage());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"us-gov-west-1", "us-gov-east-1", "cn-north-1", "cn-northwest-1"})
|
||||
void listingIsRejectedWhereFunctionUrlsAreUnavailable(String region) throws IOException {
|
||||
try (LambdaClient regional = AwsTestClients.create(
|
||||
LambdaClient.builder(), ACCOUNT, Region.of(region), endpoint)) {
|
||||
String arn = createFunction(regional, functionName, ACCOUNT, Region.of(region));
|
||||
for (String reference : List.of(functionName, arn, ACCOUNT + ":function:" + functionName)) {
|
||||
InvalidParameterValueException unavailable = assertThrows(InvalidParameterValueException.class,
|
||||
() -> regional.listFunctionUrlConfigs(request -> request.functionName(reference)));
|
||||
assertEquals(400, unavailable.statusCode());
|
||||
}
|
||||
assertEquals(arn, regional.getFunction(request -> request.functionName(functionName))
|
||||
.configuration().functionArn());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void listsStoredLatestAndAliasConfigurationsThroughAllDocumentedNameForms() {
|
||||
createUrls();
|
||||
for (String reference : List.of(functionName, functionArn, ACCOUNT + ":function:" + functionName)) {
|
||||
List<FunctionUrlConfig> configs = client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(reference)).functionUrlConfigs();
|
||||
assertEquals(List.of(functionArn, functionArn + ":blue", functionArn + ":green"),
|
||||
configs.stream().map(FunctionUrlConfig::functionArn).sorted().toList());
|
||||
FunctionUrlConfig blue = configs.stream().filter(config -> config.functionArn().endsWith(":blue"))
|
||||
.findFirst().orElseThrow();
|
||||
assertEquals(FunctionUrlAuthType.NONE, blue.authType());
|
||||
assertEquals(List.of("https://example.invalid"), blue.cors().allowOrigins());
|
||||
assertEquals(client.getFunctionUrlConfig(request -> request
|
||||
.functionName(functionName).qualifier("blue")).functionUrl(), blue.functionUrl());
|
||||
assertNotNull(blue.creationTime());
|
||||
assertNotNull(blue.lastModifiedTime());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void sdkPaginatorTraversesEveryConfigAndUpdatesAndDeletesAreVisible() {
|
||||
createUrls();
|
||||
List<FunctionUrlConfig> all = client.listFunctionUrlConfigsPaginator(request -> request
|
||||
.functionName(functionName).maxItems(1)).stream()
|
||||
.flatMap(page -> page.functionUrlConfigs().stream()).toList();
|
||||
assertEquals(3, all.size());
|
||||
assertEquals(3, all.stream().map(FunctionUrlConfig::functionArn).distinct().count());
|
||||
client.updateFunctionUrlConfig(request -> request.functionName(functionName).qualifier("blue")
|
||||
.authType(FunctionUrlAuthType.AWS_IAM).cors(cors -> cors.allowOrigins("https://updated.invalid")));
|
||||
FunctionUrlConfig updated = client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName).maxItems(50)).functionUrlConfigs().stream()
|
||||
.filter(config -> config.functionArn().endsWith(":blue")).findFirst().orElseThrow();
|
||||
assertEquals(FunctionUrlAuthType.AWS_IAM, updated.authType());
|
||||
assertEquals(List.of("https://updated.invalid"), updated.cors().allowOrigins());
|
||||
client.deleteFunctionUrlConfig(request -> request.functionName(functionName).qualifier("blue"));
|
||||
client.deleteAlias(request -> request.functionName(functionName).name("green"));
|
||||
ListFunctionUrlConfigsResponse remaining = client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName));
|
||||
assertEquals(List.of(functionArn), remaining.functionUrlConfigs().stream()
|
||||
.map(FunctionUrlConfig::functionArn).toList());
|
||||
assertNull(remaining.nextMarker());
|
||||
client.deleteFunctionUrlConfig(request -> request.functionName(functionName));
|
||||
assertTrue(client.listFunctionUrlConfigs(request -> request.functionName(functionName))
|
||||
.functionUrlConfigs().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageCanResumeAfterThePreviouslyReturnedUrlIsDeleted() {
|
||||
createUrls();
|
||||
ListFunctionUrlConfigsResponse first = client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName).maxItems(1));
|
||||
assertEquals(List.of(functionArn), first.functionUrlConfigs().stream()
|
||||
.map(FunctionUrlConfig::functionArn).toList());
|
||||
assertNotNull(first.nextMarker());
|
||||
client.deleteFunctionUrlConfig(request -> request.functionName(functionName));
|
||||
ListFunctionUrlConfigsResponse remaining = client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName).marker(first.nextMarker()).maxItems(2));
|
||||
assertEquals(List.of(functionArn + ":blue", functionArn + ":green"),
|
||||
remaining.functionUrlConfigs().stream().map(FunctionUrlConfig::functionArn).toList());
|
||||
assertNull(remaining.nextMarker());
|
||||
}
|
||||
|
||||
@Test
|
||||
void configurationsAndMarkersAreScopedToFunctionAccountAndRegion() throws IOException {
|
||||
createUrls();
|
||||
String marker = client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName).maxItems(1)).nextMarker();
|
||||
String otherName = functionName + "-other";
|
||||
createFunction(client, otherName, ACCOUNT, Region.of(REGION));
|
||||
assertThrows(InvalidParameterValueException.class, () -> client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(otherName).marker(marker)));
|
||||
try (LambdaClient otherAccount = AwsTestClients.create(LambdaClient.builder(),
|
||||
"741681410002", Region.of(REGION), endpoint);
|
||||
LambdaClient otherRegion = AwsTestClients.create(LambdaClient.builder(),
|
||||
ACCOUNT, Region.US_EAST_1, endpoint)) {
|
||||
for (LambdaClient other : List.of(otherAccount, otherRegion)) {
|
||||
assertThrows(ResourceNotFoundException.class, () -> other.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName)));
|
||||
}
|
||||
createFunction(otherAccount, functionName, "741681410002", Region.of(REGION));
|
||||
createFunction(otherRegion, functionName, ACCOUNT, Region.US_EAST_1);
|
||||
for (LambdaClient other : List.of(otherAccount, otherRegion)) {
|
||||
assertTrue(other.listFunctionUrlConfigs(request -> request.functionName(functionName))
|
||||
.functionUrlConfigs().isEmpty());
|
||||
assertThrows(InvalidParameterValueException.class, () -> other.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName).marker(marker)));
|
||||
}
|
||||
ResourceNotFoundException missing = assertThrows(ResourceNotFoundException.class,
|
||||
() -> otherAccount.listFunctionUrlConfigs(request -> request.functionName(functionArn)));
|
||||
assertEquals("Function not found: " + functionArn, missing.awsErrorDetails().errorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"", "not-a-marker", "%%%"})
|
||||
void rejectsInvalidMarkers(String marker) {
|
||||
InvalidParameterValueException invalid = assertThrows(InvalidParameterValueException.class,
|
||||
() -> client.listFunctionUrlConfigs(request -> request.functionName(functionName).marker(marker)));
|
||||
assertEquals(400, invalid.statusCode());
|
||||
assertEquals("Invalid pagination key.", invalid.awsErrorDetails().errorMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aForeignPartitionArnCannotSelectTheCallersFunction() {
|
||||
createUrls();
|
||||
String foreignArn = functionArn.replace("arn:aws:", "arn:aws-cn:");
|
||||
ResourceNotFoundException missing = assertThrows(ResourceNotFoundException.class,
|
||||
() -> client.listFunctionUrlConfigs(request -> request.functionName(foreignArn)));
|
||||
assertEquals("Function not found: " + foreignArn, missing.awsErrorDetails().errorMessage());
|
||||
assertEquals(3, client.listFunctionUrlConfigs(request -> request.functionName(functionArn))
|
||||
.functionUrlConfigs().size());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"1", "$LATEST"})
|
||||
void rejectsQualifiersOutsideTheFunctionUrlNameShape(String qualifier) {
|
||||
LambdaException invalid = assertThrows(LambdaException.class, () -> client.listFunctionUrlConfigs(request -> request
|
||||
.functionName(functionName + ":" + qualifier)));
|
||||
assertEquals(400, invalid.statusCode());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, -1, 51})
|
||||
void invalidPageSizesReturnModeledJsonErrors(int maxItems) {
|
||||
String bound = maxItems < 1 ? "greater than or equal to 1" : "less than or equal to 50";
|
||||
given().port(endpoint.getPort()).header("Authorization", AUTH).queryParam("MaxItems", maxItems)
|
||||
.get("/2021-10-31/functions/" + functionName + "/urls")
|
||||
.then().statusCode(400).body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo("1 validation error detected: Value '" + maxItems
|
||||
+ "' at 'maxItems' failed to satisfy constraint: Member must have value " + bound));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"2147483648", "1.5", "invalid"})
|
||||
void nonIntegerPageSizesReturnSerializationErrors(String maxItems) {
|
||||
given().port(endpoint.getPort()).header("Authorization", AUTH).queryParam("MaxItems", maxItems)
|
||||
.get("/2021-10-31/functions/" + functionName + "/urls")
|
||||
.then().statusCode(400).body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("'" + maxItems + "' can not be converted to Integer"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, -1, 51})
|
||||
void sdkReportsPageSizeValidationErrors(int maxItems) {
|
||||
LambdaException invalid = assertThrows(LambdaException.class,
|
||||
() -> client.listFunctionUrlConfigs(request -> request.functionName(functionName).maxItems(maxItems)));
|
||||
assertEquals(400, invalid.statusCode());
|
||||
assertEquals("ValidationException", invalid.awsErrorDetails().errorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyPageSizeUsesTheDefault() {
|
||||
createUrls();
|
||||
given().port(endpoint.getPort()).header("Authorization", AUTH).queryParam("MaxItems", "")
|
||||
.get("/2021-10-31/functions/" + functionName + "/urls")
|
||||
.then().statusCode(200).body("FunctionUrlConfigs.size()", equalTo(3));
|
||||
}
|
||||
|
||||
private void createUrls() {
|
||||
client.createFunctionUrlConfig(request -> request.functionName(functionName).authType(FunctionUrlAuthType.AWS_IAM));
|
||||
for (String alias : List.of("blue", "green", "without-url")) {
|
||||
client.createAlias(request -> request.functionName(functionName).name(alias).functionVersion("1"));
|
||||
if (!alias.equals("without-url")) {
|
||||
client.createFunctionUrlConfig(request -> request.functionName(functionName).qualifier(alias)
|
||||
.authType(FunctionUrlAuthType.NONE).cors(cors -> cors.allowOrigins("https://example.invalid")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String createFunction(LambdaClient target, String name, String account, Region region) throws IOException {
|
||||
return LambdaFunctionUrlFixtures.createFunction(target, name, account, region, endpoint, cleanup);
|
||||
}
|
||||
}
|
||||
+1
-14
@@ -8,10 +8,7 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Base64;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
@@ -31,20 +28,10 @@ class LambdaPermissionTagLayerIntegrationTest {
|
||||
|
||||
// ── setup ─────────────────────────────────────────────────────────────────
|
||||
|
||||
private static byte[] minimalZip() throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
zos.putNextEntry(new ZipEntry("index.js"));
|
||||
zos.write("exports.handler = async () => ({});".getBytes());
|
||||
zos.closeEntry();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createFunction() throws Exception {
|
||||
byte[] zip = minimalZip();
|
||||
byte[] zip = LambdaCodeFixtures.nodeJsZip("exports.handler = async () => ({});");
|
||||
String zipBase64 = Base64.getEncoder().encodeToString(zip);
|
||||
|
||||
given()
|
||||
|
||||
@@ -6,10 +6,6 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@@ -26,18 +22,6 @@ class LambdaS3CodeIntegrationTest {
|
||||
private static final String KEY_V2 = "functions/hello-s3-v2.zip";
|
||||
private static final String FN = "hello-s3";
|
||||
|
||||
// ── helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
private static byte[] makeZip(String handlerJs) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
zos.putNextEntry(new ZipEntry("index.js"));
|
||||
zos.write(handlerJs.getBytes());
|
||||
zos.closeEntry();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
// ── setup ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@@ -53,7 +37,7 @@ class LambdaS3CodeIntegrationTest {
|
||||
@Test
|
||||
@Order(2)
|
||||
void uploadCodeZipToS3() throws Exception {
|
||||
byte[] zip = makeZip("exports.handler = async (e) => ({ statusCode: 200, body: 's3-v1' });");
|
||||
byte[] zip = LambdaCodeFixtures.nodeJsZip("exports.handler = async (e) => ({ statusCode: 200, body: 's3-v1' });");
|
||||
given()
|
||||
.contentType("application/octet-stream")
|
||||
.body(zip)
|
||||
@@ -108,7 +92,7 @@ class LambdaS3CodeIntegrationTest {
|
||||
@Test
|
||||
@Order(5)
|
||||
void uploadUpdatedCodeZipToS3() throws Exception {
|
||||
byte[] zip = makeZip("exports.handler = async (e) => ({ statusCode: 200, body: 's3-v2' });");
|
||||
byte[] zip = LambdaCodeFixtures.nodeJsZip("exports.handler = async (e) => ({ statusCode: 200, body: 's3-v2' });");
|
||||
given()
|
||||
.contentType("application/octet-stream")
|
||||
.body(zip)
|
||||
|
||||
Reference in new issue
Block a user