Skip to content

Commit

Permalink
feat(AWS SQS): Support functions[].events[].sqs.maximumConcurrency
Browse files Browse the repository at this point in the history
(PR #11678)
  • Loading branch information
jasonrowsell committed Jan 18, 2023
1 parent 99cd9e6 commit 57f2719
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/providers/aws/events/sqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ functions:
- a: [1, 2]
```

## Setting the Maximum Concurrency

The maximum concurrency setting limits the number of concurrent instances of the function that an Amazon SQS event source can invoke. The minimum limit of concurrent functions that the event source can invoke is `2`, and the maximum is `1000`. To turn off maximum concurrency, leave this field empty.

For more details, see the [AWS SQS max concurrency documentation](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#events-sqs-max-concurrency).

```yml
functions:
onlyOneOrTwo:
handler: handler.preprocess
events:
- sqs:
arn: arn:aws:sqs:region:XXXXXX:myQueue
maximumConcurrency: 250
```

## IAM Permissions

The Serverless Framework will automatically configure the most minimal set of IAM permissions for you. However you can still add additional permissions if you need to. Read the official [AWS documentation](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-configure-lambda-function-trigger.html) for more information about IAM Permissions for SQS events.
Expand Down
7 changes: 7 additions & 0 deletions lib/plugins/aws/package/compile/events/sqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AwsCompileSQSEvents {
maximumBatchingWindow: { type: 'integer', minimum: 0, maximum: 300 },
functionResponseType: { enum: ['ReportBatchItemFailures'] },
filterPatterns: { $ref: '#/definitions/filterPatterns' },
maximumConcurrency: { type: 'integer', minimum: 2, maximum: 1000 },
},
required: ['arn'],
additionalProperties: false,
Expand Down Expand Up @@ -111,6 +112,12 @@ class AwsCompileSQSEvents {
};
}

if (event.sqs.maximumConcurrency) {
sqsTemplate.Properties.ScalingConfig = {
MaximumConcurrency: event.sqs.maximumConcurrency,
};
}

// add event source ARNs to PolicyDocument statements
sqsStatement.Resource.push(EventSourceArn);

Expand Down
7 changes: 7 additions & 0 deletions test/unit/lib/plugins/aws/package/compile/events/sqs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe('test/unit/lib/plugins/aws/package/compile/events/sqs.test.js', () => {
batchSize: 10,
maximumBatchingWindow: 100,
filterPatterns: [{ a: [1, 2] }, { b: [3, 4] }],
maximumConcurrency: 250,
},
},
],
Expand Down Expand Up @@ -246,6 +247,12 @@ describe('test/unit/lib/plugins/aws/package/compile/events/sqs.test.js', () => {
],
});
});

it('should have correct maximum concurrency', () => {
expect(eventSourceMappingResource.Properties.ScalingConfig).to.deep.equal({
MaximumConcurrency: 250,
});
});
});

it('should not depend on default IAM role when custom role defined', async () => {
Expand Down

0 comments on commit 57f2719

Please sign in to comment.