Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lambda worker - support maxConcurrency (SqsEventSource) #86

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the default value maxConcurrency gets set to if you don't specify a value?
does it need a default value i.e. maxConcurrency: props.lambdaProps.queueMaxConcurrency ?? <some default>, or do we only set the property if a value for queueMaxConcurrency is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, maxConcurrency has no specific limit - uses up to maximum concurrency allowed by AWS.
I would add default value only if we internally know that there is some value that suits us for our use cases. Otherwise, I think that just forwarding a parameter and leaving default behavior is the best option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not make this an optional property, lets make it a mandatory property. This is a breaking change, but will force us to enumerate the max concurrency for every use case, which is actually the right thing to do.

}),
);
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
Loading