mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
Fix/lambda incorrect size limit (#674)
* fix(http): remove 8 KB per-attribute limit on form-encoded request bodies Vert.x 4.x defaults HttpServerOptions.maxFormAttributeSize to a small value (effectively 8 KB via the Netty AbstractHttpData limit). This causes any request with Content-Type: application/x-www-form-urlencoded that carries a single attribute larger than the limit to be rejected with "Size exceed allowed maximum capacity". Two places fixed: - HttpOptionsCustomizer (new CDI bean): sets maxFormAttributeSize=-1 on the main Quarkus HTTP server so large form-encoded AWS Query Protocol requests (CloudFormation templates, EC2 UserData in base64, large IAM policies, etc.) are accepted. The overall body size is still bounded by quarkus.http.limits.max-body-size (512 MB). - RuntimeApiServer: passes HttpServerOptions with maxFormAttributeSize=-1 when creating the per-container Vert.x HTTP server. This fixes the case where the Lambda runtime posts a large synchronous response body (e.g. a 5 MB base64 payload) back to the Runtime API endpoint and the body is incorrectly decoded through the form attribute path. * fix(lambda): enforce AWS invoke payload size limits (sync 6 MB, async 1 MB) Rejects oversized invocation requests with HTTP 413 RequestTooLargeException before dispatching to the container, matching the AWS Lambda API contract. Also enforces the 6 MB sync response limit after the function returns. * test(lambda): add tests for invoke payload size limits Unit/integration tests (LambdaIntegrationTest) cover sync >6 MB and async >1 MB request rejections plus boundary-at-limit acceptance. Compat test (LambdaPayloadSizeLimitTest) uses the Java SDK to verify RequestTooLargeException is surfaced correctly, including a Docker-gated test for the 6 MB response limit. * test(lambda): add regression test for 5 MB response via RuntimeApiServer Verifies that a sync invocation returning a 5 MB body (within the 6 MB AWS limit) succeeds end-to-end. Without the maxFormAttributeSize fix on the RuntimeApiServer, the Lambda runtime's POST of the large response body was rejected by Netty's 8 KB form-attribute cap, crashing the request with "Size exceed allowed maximum capacity".
This commit is contained in:
6 files changed
+300
-1
No files matched your search
+162
@@ -0,0 +1,162 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.core.SdkBytes;
|
||||
import software.amazon.awssdk.core.exception.ApiCallTimeoutException;
|
||||
import software.amazon.awssdk.services.lambda.LambdaClient;
|
||||
import software.amazon.awssdk.services.lambda.model.*;
|
||||
import software.amazon.awssdk.services.lambda.model.Runtime;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Lambda - Invoke payload size limits")
|
||||
class LambdaPayloadSizeLimitTest {
|
||||
|
||||
private static final int _1_MB = 1 * 1024 * 1024;
|
||||
private static final int _6_MB = 6 * 1024 * 1024;
|
||||
|
||||
private static final int _5_MB = 5 * 1024 * 1024;
|
||||
|
||||
private static final String FN = "sdk-size-limit-fn";
|
||||
private static final String FN_LARGE = "sdk-size-limit-large-response-fn";
|
||||
private static final String FN_5MB = "sdk-size-limit-5mb-response-fn";
|
||||
private static final String ROLE = "arn:aws:iam::000000000000:role/lambda-role";
|
||||
|
||||
private static LambdaClient lambda;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
lambda = TestFixtures.lambdaClient();
|
||||
lambda.createFunction(CreateFunctionRequest.builder()
|
||||
.functionName(FN)
|
||||
.runtime(Runtime.NODEJS20_X)
|
||||
.role(ROLE)
|
||||
.handler("index.handler")
|
||||
.code(FunctionCode.builder()
|
||||
.zipFile(SdkBytes.fromByteArray(LambdaUtils.minimalZip()))
|
||||
.build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (lambda == null) return;
|
||||
for (String name : new String[]{FN, FN_LARGE, FN_5MB}) {
|
||||
try { lambda.deleteFunction(DeleteFunctionRequest.builder().functionName(name).build()); }
|
||||
catch (Exception ignored) {}
|
||||
}
|
||||
lambda.close();
|
||||
}
|
||||
|
||||
// ── Request payload limits ──────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@DisplayName("sync invoke with payload > 6 MB returns 413 RequestTooLargeException")
|
||||
void syncInvoke_payloadExceeds6MB_throwsRequestTooLargeException() {
|
||||
assertThatThrownBy(() -> lambda.invoke(InvokeRequest.builder()
|
||||
.functionName(FN)
|
||||
.invocationType(InvocationType.REQUEST_RESPONSE)
|
||||
.payload(SdkBytes.fromByteArray(new byte[_6_MB + 1]))
|
||||
.build()))
|
||||
.isInstanceOf(RequestTooLargeException.class)
|
||||
.satisfies(ex -> assertThat(((RequestTooLargeException) ex).statusCode()).isEqualTo(413));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("sync invoke with payload exactly 6 MB is not rejected by size check")
|
||||
void syncInvoke_payloadExactly6MB_isNotRejected() {
|
||||
// DryRun avoids waiting for Lambda dispatch; verifies no 413 from size check
|
||||
InvokeResponse resp = lambda.invoke(InvokeRequest.builder()
|
||||
.functionName(FN)
|
||||
.invocationType(InvocationType.DRY_RUN)
|
||||
.payload(SdkBytes.fromByteArray(new byte[_6_MB]))
|
||||
.build());
|
||||
|
||||
assertThat(resp.statusCode()).isEqualTo(204);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("async invoke with payload > 1 MB returns 413 RequestTooLargeException")
|
||||
void asyncInvoke_payloadExceeds1MB_throwsRequestTooLargeException() {
|
||||
assertThatThrownBy(() -> lambda.invoke(InvokeRequest.builder()
|
||||
.functionName(FN)
|
||||
.invocationType(InvocationType.EVENT)
|
||||
.payload(SdkBytes.fromByteArray(new byte[_1_MB + 1]))
|
||||
.build()))
|
||||
.isInstanceOf(RequestTooLargeException.class)
|
||||
.satisfies(ex -> assertThat(((RequestTooLargeException) ex).statusCode()).isEqualTo(413));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("async invoke with payload exactly 1 MB is accepted (202)")
|
||||
void asyncInvoke_payloadExactly1MB_isAccepted() {
|
||||
InvokeResponse resp = lambda.invoke(InvokeRequest.builder()
|
||||
.functionName(FN)
|
||||
.invocationType(InvocationType.EVENT)
|
||||
.payload(SdkBytes.fromByteArray(new byte[_1_MB]))
|
||||
.build());
|
||||
|
||||
assertThat(resp.statusCode()).isEqualTo(202);
|
||||
}
|
||||
|
||||
// ── Response payload limit ──────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
@DisplayName("sync invoke returning > 6 MB response returns 413 RequestTooLargeException")
|
||||
void syncInvoke_responseExceeds6MB_throwsRequestTooLargeException() {
|
||||
Assumptions.assumeTrue(TestFixtures.isLambdaDispatchAvailable(),
|
||||
"skipping: Lambda dispatch (Docker) not available in this environment");
|
||||
|
||||
lambda.createFunction(CreateFunctionRequest.builder()
|
||||
.functionName(FN_LARGE)
|
||||
.runtime(Runtime.NODEJS20_X)
|
||||
.role(ROLE)
|
||||
.handler("index.handler")
|
||||
.code(FunctionCode.builder()
|
||||
.zipFile(SdkBytes.fromByteArray(LambdaUtils.largeResponseZip(_6_MB + 1)))
|
||||
.build())
|
||||
.build());
|
||||
|
||||
assertThatThrownBy(() -> lambda.invoke(InvokeRequest.builder()
|
||||
.functionName(FN_LARGE)
|
||||
.invocationType(InvocationType.REQUEST_RESPONSE)
|
||||
.payload(SdkBytes.fromUtf8String("{}"))
|
||||
.overrideConfiguration(c -> c.apiCallTimeout(Duration.ofSeconds(60)))
|
||||
.build()))
|
||||
.isInstanceOf(RequestTooLargeException.class)
|
||||
.satisfies(ex -> assertThat(((RequestTooLargeException) ex).statusCode()).isEqualTo(413));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("sync invoke returning a 5 MB response succeeds (regression: RuntimeApiServer crashed on bodies > 8 KB via form-limit bug)")
|
||||
void syncInvoke_5MBResponse_isReturnedSuccessfully() {
|
||||
Assumptions.assumeTrue(TestFixtures.isLambdaDispatchAvailable(),
|
||||
"skipping: Lambda dispatch (Docker) not available in this environment");
|
||||
|
||||
// 5 MB is within the 6 MB AWS limit but well above the 8 KB Netty form-attribute
|
||||
// cap that previously caused "Size exceed allowed maximum capacity" when the Lambda
|
||||
// runtime POSTed a large response body back to the RuntimeApiServer.
|
||||
lambda.createFunction(CreateFunctionRequest.builder()
|
||||
.functionName(FN_5MB)
|
||||
.runtime(Runtime.NODEJS20_X)
|
||||
.role(ROLE)
|
||||
.handler("index.handler")
|
||||
.code(FunctionCode.builder()
|
||||
.zipFile(SdkBytes.fromByteArray(LambdaUtils.largeResponseZip(_5_MB)))
|
||||
.build())
|
||||
.build());
|
||||
|
||||
InvokeResponse resp = lambda.invoke(InvokeRequest.builder()
|
||||
.functionName(FN_5MB)
|
||||
.invocationType(InvocationType.REQUEST_RESPONSE)
|
||||
.payload(SdkBytes.fromUtf8String("{}"))
|
||||
.overrideConfiguration(c -> c.apiCallTimeout(Duration.ofSeconds(60)))
|
||||
.build());
|
||||
|
||||
assertThat(resp.statusCode()).isEqualTo(200);
|
||||
assertThat(resp.functionError()).isNull();
|
||||
assertThat(resp.payload().asByteArray().length).isGreaterThan(_5_MB - 100);
|
||||
}
|
||||
}
|
||||
@@ -178,6 +178,17 @@ public final class LambdaUtils {
|
||||
return createZip("index.js", code);
|
||||
}
|
||||
|
||||
/**
|
||||
* ZIP containing a Node.js handler that returns a payload of {@code bytes} 'x' characters.
|
||||
* Used to test response payload size limit enforcement.
|
||||
*/
|
||||
public static byte[] largeResponseZip(int bytes) {
|
||||
String code = """
|
||||
exports.handler = async () => 'x'.repeat(%d);
|
||||
""".formatted(bytes);
|
||||
return createZip("index.js", code);
|
||||
}
|
||||
|
||||
private static byte[] createZip(String filename, String content) {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
Reference in new issue
Block a user