Skip to content

Commit 1e786ed

Browse files
authored
Merge pull request #317 from joawan/master
2 parents aaa3588 + 1cdc132 commit 1e786ed

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

docs/queue.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ By default, Lift configures Lambda to be invoked with 1 messages at a time. The
372372

373373
Note you can use [partial batch failures](#partial-batch-failures) to avoid failing the whole batch.
374374

375-
It is possible to set the batch size between 1 and 10.
375+
It is possible to set the batch size between 1 and 10 for FIFO queues and 10000 for regular queues.
376+
For batch size over 10, [maxBatchingWindow](#maximum-batching-window) must be set.
376377

377378
### Max Concurrency
378379

src/constructs/aws/Queue.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const QUEUE_DEFINITION = {
4343
batchSize: {
4444
type: "number",
4545
minimum: 1,
46-
maximum: 10,
46+
maximum: 10000,
4747
},
4848
maxBatchingWindow: {
4949
type: "number",
@@ -167,6 +167,23 @@ export class Queue extends AwsConstruct {
167167
delay = Duration.seconds(configuration.delay);
168168
}
169169

170+
if (configuration.batchSize !== undefined) {
171+
if (configuration.batchSize > 10 && configuration.fifo === true) {
172+
throw new ServerlessError(
173+
`Invalid configuration in 'constructs.${this.id}': 'batchSize' must be between 0 and 10 for FIFO queues, '${configuration.batchSize}' given.`,
174+
"LIFT_INVALID_CONSTRUCT_CONFIGURATION"
175+
);
176+
}
177+
if (configuration.batchSize > 10 && !this.getMaximumBatchingWindow()) {
178+
throw new ServerlessError(
179+
`Invalid configuration in 'constructs.${
180+
this.id
181+
}': 'maxBatchingWindow' must be greater than 0 for batchSize > 10, '${this.getMaximumBatchingWindow()}' given.`,
182+
"LIFT_INVALID_CONSTRUCT_CONFIGURATION"
183+
);
184+
}
185+
}
186+
170187
let encryption = undefined;
171188
if (isNil(configuration.encryption) || configuration.encryption.length === 0) {
172189
encryption = {};

test/unit/queues.test.ts

+49
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,53 @@ describe("queues", () => {
701701
);
702702
}
703703
});
704+
705+
it("should throw if batch size is over 10 for FIFO queues", async () => {
706+
expect.assertions(2);
707+
708+
try {
709+
await runServerless({
710+
fixture: "queues",
711+
configExt: merge({}, pluginConfigExt, {
712+
constructs: {
713+
emails: {
714+
batchSize: 100,
715+
fifo: true,
716+
},
717+
},
718+
}),
719+
command: "package",
720+
});
721+
} catch (error) {
722+
expect(error).toBeInstanceOf(ServerlessError);
723+
expect(error).toHaveProperty(
724+
"message",
725+
"Invalid configuration in 'constructs.emails': 'batchSize' must be between 0 and 10 for FIFO queues, '100' given."
726+
);
727+
}
728+
});
729+
730+
it("should throw if batch size is over 10 and maxBatchWindow is not set", async () => {
731+
expect.assertions(2);
732+
733+
try {
734+
await runServerless({
735+
fixture: "queues",
736+
configExt: merge({}, pluginConfigExt, {
737+
constructs: {
738+
emails: {
739+
batchSize: 100,
740+
},
741+
},
742+
}),
743+
command: "package",
744+
});
745+
} catch (error) {
746+
expect(error).toBeInstanceOf(ServerlessError);
747+
expect(error).toHaveProperty(
748+
"message",
749+
"Invalid configuration in 'constructs.emails': 'maxBatchingWindow' must be greater than 0 for batchSize > 10, '0' given."
750+
);
751+
}
752+
});
704753
});

0 commit comments

Comments
 (0)