Skip to content

Commit

Permalink
Merge branch 'getlift:master' into server-side-website-merge-custom-s…
Browse files Browse the repository at this point in the history
…3-origins
  • Loading branch information
aran112000 authored Jun 16, 2023
2 parents 1858711 + 1e786ed commit 14993f6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
3 changes: 2 additions & 1 deletion docs/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ By default, Lift configures Lambda to be invoked with 1 messages at a time. The

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

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

### Max Concurrency

Expand Down
5 changes: 1 addition & 4 deletions src/classes/cloudfrontFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import ServerlessError from "../utils/error";

export function redirectToMainDomain(domains: string[] | undefined): string {
if (domains === undefined || domains.length < 2) {
throw new ServerlessError(
`Invalid value in 'redirectToMainDomain': you must have at least 2 domains configured to enable redirection to the main domain.`,
"LIFT_INVALID_CONSTRUCT_CONFIGURATION"
);
return "";
}

const mainDomain = domains[0];
Expand Down
1 change: 1 addition & 0 deletions src/constructs/aws/DatabaseDynamoDBSingleTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class DatabaseDynamoDBSingleTable extends AwsConstruct {
"dynamodb:DeleteItem",
"dynamodb:BatchWriteItem",
"dynamodb:UpdateItem",
"dynamodb:ConditionCheckItem",
],
[this.table.tableArn, Stack.of(this).resolve(Fn.join("/", [this.table.tableArn, "index", "*"]))]
),
Expand Down
22 changes: 20 additions & 2 deletions src/constructs/aws/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { CfnQueue } from "aws-cdk-lib/aws-sqs";
import { Queue as CdkQueue, QueueEncryption } from "aws-cdk-lib/aws-sqs";
import type { FromSchema } from "json-schema-to-ts";
import type { CfnAlarm } from "aws-cdk-lib/aws-cloudwatch";
import { Alarm, ComparisonOperator, Metric } from "aws-cdk-lib/aws-cloudwatch";
import { Alarm, ComparisonOperator, Metric, TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
import { Subscription, SubscriptionProtocol, Topic } from "aws-cdk-lib/aws-sns";
import type { AlarmActionConfig } from "aws-cdk-lib/aws-cloudwatch/lib/alarm-action";
import type { Construct as CdkConstruct } from "constructs";
Expand Down Expand Up @@ -43,7 +43,7 @@ const QUEUE_DEFINITION = {
batchSize: {
type: "number",
minimum: 1,
maximum: 10,
maximum: 10000,
},
maxBatchingWindow: {
type: "number",
Expand Down Expand Up @@ -167,6 +167,23 @@ export class Queue extends AwsConstruct {
delay = Duration.seconds(configuration.delay);
}

if (configuration.batchSize !== undefined) {
if (configuration.batchSize > 10 && configuration.fifo === true) {
throw new ServerlessError(
`Invalid configuration in 'constructs.${this.id}': 'batchSize' must be between 0 and 10 for FIFO queues, '${configuration.batchSize}' given.`,
"LIFT_INVALID_CONSTRUCT_CONFIGURATION"
);
}
if (configuration.batchSize > 10 && !this.getMaximumBatchingWindow()) {
throw new ServerlessError(
`Invalid configuration in 'constructs.${
this.id
}': 'maxBatchingWindow' must be greater than 0 for batchSize > 10, '${this.getMaximumBatchingWindow()}' given.`,
"LIFT_INVALID_CONSTRUCT_CONFIGURATION"
);
}
}

let encryption = undefined;
if (isNil(configuration.encryption) || configuration.encryption.length === 0) {
encryption = {};
Expand Down Expand Up @@ -241,6 +258,7 @@ export class Queue extends AwsConstruct {
// Alert as soon as we have 1 message in the DLQ
threshold: 0,
comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
treatMissingData: TreatMissingData.NOT_BREACHING,
});
this.alarm.addAlarmAction({
bind(): AlarmActionConfig {
Expand Down
50 changes: 50 additions & 0 deletions test/unit/queues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ describe("queues", () => {
Period: 60,
Statistic: "Sum",
Threshold: 0,
TreatMissingData: "notBreaching",
},
});
expect(cfTemplate.Resources[computeLogicalId("emails", "AlarmTopic")]).toMatchObject({
Expand Down Expand Up @@ -700,4 +701,53 @@ describe("queues", () => {
);
}
});

it("should throw if batch size is over 10 for FIFO queues", async () => {
expect.assertions(2);

try {
await runServerless({
fixture: "queues",
configExt: merge({}, pluginConfigExt, {
constructs: {
emails: {
batchSize: 100,
fifo: true,
},
},
}),
command: "package",
});
} catch (error) {
expect(error).toBeInstanceOf(ServerlessError);
expect(error).toHaveProperty(
"message",
"Invalid configuration in 'constructs.emails': 'batchSize' must be between 0 and 10 for FIFO queues, '100' given."
);
}
});

it("should throw if batch size is over 10 and maxBatchWindow is not set", async () => {
expect.assertions(2);

try {
await runServerless({
fixture: "queues",
configExt: merge({}, pluginConfigExt, {
constructs: {
emails: {
batchSize: 100,
},
},
}),
command: "package",
});
} catch (error) {
expect(error).toBeInstanceOf(ServerlessError);
expect(error).toHaveProperty(
"message",
"Invalid configuration in 'constructs.emails': 'maxBatchingWindow' must be greater than 0 for batchSize > 10, '0' given."
);
}
});
});

0 comments on commit 14993f6

Please sign in to comment.