Skip to content

Commit

Permalink
feat: lambda worker - support maxConcurrency (SqsEventSource) (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanja-kovacevic-thinkit authored Apr 3, 2024
1 parent bc3a840 commit dd53d96
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class ContainerLambdaWorkerStack extends cdk.Stack {
{
name: `${prefix}container-lambda-worker`,
lambdaProps: {
queueMaxConcurrency: 100,
environment: {
EXAMPLE_ENV_VAR: "example value",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class SimpleLambdaWorkerStack extends cdk.Stack {
{
name: `${prefix}simple-lambda-worker`,
lambdaProps: {
queueMaxConcurrency: 5,
environment: {
EXAMPLE_ENV_VAR: "example value",
SUCCESS_QUEUE_URL: successQueue.queueUrl,
Expand Down
1 change: 1 addition & 0 deletions lib/lambda-worker/lambda-worker-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface LambdaWorkerProps {
timeout: cdk.Duration;
vpc?: ec2.IVpc;
vpcSubnets?: ec2.SubnetSelection;
queueMaxConcurrency: number;
} & Partial<FunctionLambdaProps> &
Partial<ContainerFromEcrLambdaProps> &
Partial<ContainerFromImageAssetLambdaProps>;
Expand Down
1 change: 1 addition & 0 deletions lib/lambda-worker/lambda-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export class LambdaWorker extends Construct {
new SqsEventSource(lambdaQueue, {
enabled: props.lambdaProps.enableQueue ?? true,
batchSize: 1,
maxConcurrency: props.lambdaProps.queueMaxConcurrency,
}),
);
lambdaWorker.addEventSource(
Expand Down
15 changes: 15 additions & 0 deletions test/infra/lambda-worker/lambda-worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("LambdaWorker", () => {
worker = new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
entry: "examples/simple-lambda-worker/src/lambda/simple-worker.js",
handler: "testWorker",
memorySize: 2048,
Expand Down Expand Up @@ -216,6 +217,7 @@ describe("LambdaWorker", () => {
new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
entry: "examples/simple-lambda-worker/src/lambda/simple-worker.js",
handler: "testWorker",
memorySize: 2048,
Expand Down Expand Up @@ -284,6 +286,7 @@ describe("LambdaWorker", () => {
new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
entry: "examples/simple-lambda-worker/src/lambda/simple-worker.js",
handler: "testWorker",
memorySize: 2048,
Expand Down Expand Up @@ -340,6 +343,7 @@ describe("LambdaWorker", () => {
new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
entry: "examples/simple-lambda-worker/src/lambda/simple-worker.js",
handler: "testWorker",
memorySize: 2048,
Expand Down Expand Up @@ -401,6 +405,7 @@ describe("LambdaWorker", () => {
new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
entry: "examples/simple-lambda-worker/src/lambda/simple-worker.js",
handler: "testWorker",
memorySize: 2048,
Expand Down Expand Up @@ -436,6 +441,9 @@ describe("LambdaWorker", () => {
"Arn",
],
},
ScalingConfig: {
MaximumConcurrency: 5,
},
},
);
});
Expand All @@ -459,6 +467,7 @@ describe("LambdaWorker", () => {
new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
entry: "examples/simple-lambda-worker/src/lambda/simple-worker.js",
handler: "testWorker",
memorySize: 2048,
Expand Down Expand Up @@ -528,6 +537,7 @@ describe("LambdaWorker", () => {
worker = new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
dockerImageTag: "test-lambda-12345",
ecrRepositoryArn: "arn:aws:ecr:eu-west-1:012345678910:repository",
ecrRepositoryName: "repository",
Expand Down Expand Up @@ -728,6 +738,7 @@ describe("LambdaWorker", () => {
new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
dockerImageTag: "test-lambda-12345",
ecrRepositoryArn: "arn:aws:ecr:eu-west-1:012345678910:repository",
ecrRepositoryName: "repository",
Expand Down Expand Up @@ -797,6 +808,7 @@ describe("LambdaWorker", () => {
});

lambdaProps = {
queueMaxConcurrency: 5,
memorySize: 2048,
policyStatements: [
new iam.PolicyStatement({
Expand Down Expand Up @@ -901,6 +913,7 @@ describe("LambdaWorker", () => {
new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
entry: "examples/simple-lambda-worker/src/lambda/simple-worker.js",
handler: "testWorker",
memorySize: 2048,
Expand Down Expand Up @@ -931,6 +944,7 @@ describe("LambdaWorker", () => {
new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
entry: "examples/simple-lambda-worker/src/lambda/simple-worker.js",
handler: "testWorker",
memorySize: 512,
Expand Down Expand Up @@ -1041,6 +1055,7 @@ describe("LambdaWorker", () => {
new LambdaWorker(stack, "MyTestLambdaWorker", {
name: "MyTestLambdaWorker",
lambdaProps: {
queueMaxConcurrency: 5,
entry: config.entry,
handler: config.handler,
dockerCommand: config.dockerCommand,
Expand Down

0 comments on commit dd53d96

Please sign in to comment.