Skip to content

Commit 3623982

Browse files
authoredNov 30, 2021
feat(lambda-event-sources): sqs: support reportBatchItemFailures (#17733)
Fixes #17690 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 986f291 commit 3623982

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
 

‎packages/@aws-cdk/aws-lambda-event-sources/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ declare const fn: lambda.Function;
7171
fn.addEventSource(new SqsEventSource(queue, {
7272
batchSize: 10, // default
7373
maxBatchingWindow: Duration.minutes(5),
74+
reportBatchItemFailures: true, // default to false
7475
}));
7576
```
7677

‎packages/@aws-cdk/aws-lambda-event-sources/lib/sqs.ts

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ export interface SqsEventSourceProps {
2424
*/
2525
readonly maxBatchingWindow?: Duration;
2626

27+
/**
28+
* Allow functions to return partially successful responses for a batch of records.
29+
*
30+
* @see https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting
31+
*
32+
* @default false
33+
*/
34+
readonly reportBatchItemFailures?: boolean;
35+
2736
/**
2837
* If the SQS event source mapping should be enabled.
2938
*
@@ -61,6 +70,7 @@ export class SqsEventSource implements lambda.IEventSource {
6170
const eventSourceMapping = target.addEventSourceMapping(`SqsEventSource:${Names.nodeUniqueId(this.queue.node)}`, {
6271
batchSize: this.props.batchSize,
6372
maxBatchingWindow: this.props.maxBatchingWindow,
73+
reportBatchItemFailures: this.props.reportBatchItemFailures,
6474
enabled: this.props.enabled,
6575
eventSourceArn: this.queue.queueArn,
6676
});

‎packages/@aws-cdk/aws-lambda-event-sources/test/sqs.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -264,5 +264,24 @@ describe('SQSEventSource', () => {
264264
});
265265

266266

267+
});
268+
269+
test('reportBatchItemFailures', () => {
270+
// GIVEN
271+
const stack = new cdk.Stack();
272+
const fn = new TestFunction(stack, 'Fn');
273+
const q = new sqs.Queue(stack, 'Q');
274+
275+
// WHEN
276+
fn.addEventSource(new sources.SqsEventSource(q, {
277+
reportBatchItemFailures: true,
278+
}));
279+
280+
// THEN
281+
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', {
282+
'FunctionResponseTypes': ['ReportBatchItemFailures'],
283+
});
284+
285+
267286
});
268287
});

0 commit comments

Comments
 (0)
Please sign in to comment.