mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(lambda): support ScalingConfig.MaximumConcurrency on SQS event source mappings (#490)
* feat(lambda): support ScalingConfig.MaximumConcurrency on SQS event source mappings
Wire-level support for ScalingConfig on CreateEventSourceMapping,
UpdateEventSourceMapping, GetEventSourceMapping, and
ListEventSourceMappings:
- New ScalingConfig model carrying MaximumConcurrency (Integer, nullable).
- Create and Update parse ScalingConfig from the request, validate range
(2-1000), reject non-SQS event sources with InvalidParameterValueException.
- Response includes ScalingConfig only when a cap is set; omitted when
null, matching AWS behavior.
- Update with an empty ScalingConfig clears the cap (AWS reset semantics).
The value is persisted on the EventSourceMapping but not yet enforced at
invocation time — the SQS poller today serializes to one concurrent
invocation per ESM regardless. Real parallel dispatch capped by
MaximumConcurrency is a follow-up (Scope B).
Tests:
- EsmIntegrationTest: 6 new cases covering round-trip, below/above range
rejection, non-SQS rejection, omission when unset, add-then-clear via
update.
- LambdaEsmScalingConfigTest (SDK compat): 5 cases verifying SDK typed
ScalingConfig round-trips, InvalidParameterValueException on range
violations, and add/clear lifecycle via update.
* fix(lambda): reject non-integer MaximumConcurrency and ScalingConfig on non-SQS sources
- parseScalingConfig now detects fractional values (e.g. 2.5) and
returns InvalidParameterValueException instead of silently truncating.
- Empty ScalingConfig ({}) on a non-SQS event source is now rejected.
Previously the non-SQS check only fired when MaximumConcurrency was
non-null, so an empty ScalingConfig on Kinesis / DynamoDB Streams
slipped through.
- Two new integration tests cover both cases.
* fix(lambda): tighten ScalingConfig input validation
- Reject non-object ScalingConfig (e.g. "foo", []) with 400 instead of
silently treating it as absent. In update paths this previously cleared
an existing cap unintentionally.
- Reject non-numeric MaximumConcurrency (e.g. string "7"). AWS expects a
JSON number on the wire; the previous toString + parseInt path accepted
strings that real AWS would reject.
- Use longValue() before range-checking to avoid intValue() overflow on
large inputs (e.g. 5000000000) that would produce a negative value and
a misleading error message.
- Two new integration tests: string MaximumConcurrency and non-object
ScalingConfig.
* fix(lambda): add NaN/Infinity guard and expand ScalingConfig test coverage
- parseScalingConfig now explicitly rejects NaN and Infinity rather than
letting them fall through to longValue() with a misleading error.
- The post-range non-SQS guard was flagged as dead code by the reviewer
but is in fact reachable (non-SQS + valid numeric MaximumConcurrency).
Retained and confirmed by the existing @Order(43) test.
- New tests: update range validation (below/above on PUT), and list
with mixed ScalingConfig presence across ESMs.
This commit is contained in:
1 parent
ca2e5d4153
commit
d8243b8803
7 files changed
+644
-1
No files matched your search
@@ -254,4 +254,336 @@ class EsmIntegrationTest {
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
// ──────────────────────────── ScalingConfig ────────────────────────────
|
||||
|
||||
@Test
|
||||
@Order(40)
|
||||
void createEventSourceMappingWithScalingConfigRoundTrips() {
|
||||
String uuid = given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"BatchSize": 5,
|
||||
"ScalingConfig": { "MaximumConcurrency": 7 }
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.body("ScalingConfig.MaximumConcurrency", equalTo(7))
|
||||
.extract()
|
||||
.path("UUID");
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get(LAMBDA_BASE + "/event-source-mappings/" + uuid)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("ScalingConfig.MaximumConcurrency", equalTo(7));
|
||||
|
||||
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid).then().statusCode(202);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(41)
|
||||
void createEventSourceMappingRejectsMaximumConcurrencyBelowMinimum() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"ScalingConfig": { "MaximumConcurrency": 1 }
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("between 2 and 1000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(42)
|
||||
void createEventSourceMappingRejectsMaximumConcurrencyAboveMaximum() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"ScalingConfig": { "MaximumConcurrency": 1001 }
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("between 2 and 1000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(43)
|
||||
void createEventSourceMappingRejectsScalingConfigOnNonSqsSource() {
|
||||
// MaximumConcurrency is SQS-only in AWS. Kinesis uses ParallelizationFactor.
|
||||
String kinesisArn = "arn:aws:kinesis:" + REGION + ":" + ACCOUNT_ID + ":stream/irrelevant";
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"ScalingConfig": { "MaximumConcurrency": 5 }
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, kinesisArn))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("only supported for Amazon SQS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(44)
|
||||
void createEventSourceMappingRejectsEmptyScalingConfigOnNonSqsSource() {
|
||||
String kinesisArn = "arn:aws:kinesis:" + REGION + ":" + ACCOUNT_ID + ":stream/irrelevant";
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"ScalingConfig": {}
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, kinesisArn))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("only supported for Amazon SQS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(45)
|
||||
void createEventSourceMappingRejectsNonIntegerMaximumConcurrency() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"ScalingConfig": { "MaximumConcurrency": 2.5 }
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("must be an integer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(46)
|
||||
void createEventSourceMappingRejectsStringMaximumConcurrency() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"ScalingConfig": { "MaximumConcurrency": "7" }
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("numeric"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(47)
|
||||
void createEventSourceMappingRejectsNonObjectScalingConfig() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"ScalingConfig": "not-an-object"
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("JSON object"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(48)
|
||||
void responseOmitsScalingConfigWhenUnset() {
|
||||
// A mapping created without ScalingConfig should not expose the key
|
||||
// in subsequent responses — AWS omits the field rather than returning
|
||||
// an empty object.
|
||||
String uuid = given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"BatchSize": 2
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.body("$", not(hasKey("ScalingConfig")))
|
||||
.extract()
|
||||
.path("UUID");
|
||||
|
||||
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid).then().statusCode(202);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(49)
|
||||
void updateEventSourceMappingRejectsInvalidScalingConfig() {
|
||||
String uuid = given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"BatchSize": 2
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.extract()
|
||||
.path("UUID");
|
||||
|
||||
// Below minimum
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{ \"ScalingConfig\": { \"MaximumConcurrency\": 1 } }")
|
||||
.when()
|
||||
.put(LAMBDA_BASE + "/event-source-mappings/" + uuid)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("between 2 and 1000"));
|
||||
|
||||
// Above maximum
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{ \"ScalingConfig\": { \"MaximumConcurrency\": 1001 } }")
|
||||
.when()
|
||||
.put(LAMBDA_BASE + "/event-source-mappings/" + uuid)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("message", containsString("between 2 and 1000"));
|
||||
|
||||
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid).then().statusCode(202);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(50)
|
||||
void listEventSourceMappingsWithMixedScalingConfig() {
|
||||
// Create one ESM with ScalingConfig and one without.
|
||||
String uuidWith = given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"BatchSize": 3,
|
||||
"ScalingConfig": { "MaximumConcurrency": 10 }
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.extract()
|
||||
.path("UUID");
|
||||
|
||||
String uuidWithout = given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"BatchSize": 4
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.extract()
|
||||
.path("UUID");
|
||||
|
||||
// List should return both; one with ScalingConfig and one without.
|
||||
given()
|
||||
.when()
|
||||
.get(LAMBDA_BASE + "/event-source-mappings?FunctionName=" + FUNCTION_ARN)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EventSourceMappings.find { it.UUID == '" + uuidWith + "' }.ScalingConfig.MaximumConcurrency",
|
||||
equalTo(10))
|
||||
.body("EventSourceMappings.find { it.UUID == '" + uuidWithout + "' }.ScalingConfig",
|
||||
nullValue());
|
||||
|
||||
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuidWith).then().statusCode(202);
|
||||
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuidWithout).then().statusCode(202);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(51)
|
||||
void updateEventSourceMappingAddsAndClearsScalingConfig() {
|
||||
String uuid = given()
|
||||
.contentType("application/json")
|
||||
.body("""
|
||||
{
|
||||
"FunctionName": "%s",
|
||||
"EventSourceArn": "%s",
|
||||
"BatchSize": 4
|
||||
}
|
||||
""".formatted(FUNCTION_NAME, QUEUE_ARN))
|
||||
.when()
|
||||
.post(LAMBDA_BASE + "/event-source-mappings")
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.body("$", not(hasKey("ScalingConfig")))
|
||||
.extract()
|
||||
.path("UUID");
|
||||
|
||||
// Add
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{ \"ScalingConfig\": { \"MaximumConcurrency\": 3 } }")
|
||||
.when()
|
||||
.put(LAMBDA_BASE + "/event-source-mappings/" + uuid)
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.body("ScalingConfig.MaximumConcurrency", equalTo(3));
|
||||
|
||||
// Clear by sending an empty ScalingConfig (AWS semantics)
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body("{ \"ScalingConfig\": {} }")
|
||||
.when()
|
||||
.put(LAMBDA_BASE + "/event-source-mappings/" + uuid)
|
||||
.then()
|
||||
.statusCode(202)
|
||||
.body("$", not(hasKey("ScalingConfig")));
|
||||
|
||||
given().delete(LAMBDA_BASE + "/event-source-mappings/" + uuid).then().statusCode(202);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user