Skip to content

Commit

Permalink
feat(AWS SQS): Support functionResponseType (#10265)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoeft committed Nov 24, 2021
1 parent ce66591 commit 44511f3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/providers/aws/events/sqs.md
Expand Up @@ -51,7 +51,11 @@ functions:

For the SQS event integration, you can set the `batchSize`, which effects how many SQS messages can be included in a single Lambda invocation. The default `batchSize` is `10`. The max `batchSize` is `10000` for a standard queue, `10` for a FIFO queue.

You can also set `maximumBatchingWindow` to standard queues to specify the maximum amount of time in seconds to gather records before invoking the function. The max `maximumBatchingWindow` is `300` seconds. Check [AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html) for more details.
You can also set `maximumBatchingWindow` to standard queues to specify the maximum amount of time in seconds to gather records before invoking the function. The max `maximumBatchingWindow` is `300` seconds.

You can set `functionResponseType` to `ReportBatchItemFailures` to let your function return a partial success result if one or more messages in the batch have failed.

Check [AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html) for more details.

```yml
functions:
Expand All @@ -62,6 +66,7 @@ functions:
arn: arn:aws:sqs:region:XXXXXX:myQueue
batchSize: 10
maximumBatchingWindow: 60
functionResponseType: ReportBatchItemFailures
```

## IAM Permissions
Expand Down
5 changes: 5 additions & 0 deletions lib/plugins/aws/package/compile/events/sqs.js
Expand Up @@ -22,6 +22,7 @@ class AwsCompileSQSEvents {
batchSize: { type: 'integer', minimum: 1, maximum: 10000 },
enabled: { type: 'boolean' },
maximumBatchingWindow: { type: 'integer', minimum: 0, maximum: 300 },
functionResponseType: { enum: ['ReportBatchItemFailures'] },
},
required: ['arn'],
additionalProperties: false,
Expand Down Expand Up @@ -97,6 +98,10 @@ class AwsCompileSQSEvents {
},
};

if (event.sqs.functionResponseType != null) {
sqsTemplate.Properties.FunctionResponseTypes = [event.sqs.functionResponseType];
}

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

Expand Down
36 changes: 36 additions & 0 deletions test/unit/lib/plugins/aws/package/compile/events/sqs.test.js
Expand Up @@ -676,3 +676,39 @@ describe('AwsCompileSQSEvents #2', () => {
expect(eventSourceMappingResource.DependsOn).to.deep.equal([]);
});
});

describe('regular configuration', () => {
let eventSourceMappingResource;

before(async () => {
const { awsNaming, cfTemplate } = await runServerless({
fixture: 'function',
configExt: {
functions: {
basic: {
provisionedConcurrency: 1,
events: [
{
sqs: {
arn: 'arn:aws:sqs:region:account:MyQueue',
batchSize: 10,
maximumBatchingWindow: 100,
functionResponseType: 'ReportBatchItemFailures',
},
},
],
},
},
},
command: 'package',
});
const queueLogicalId = awsNaming.getQueueLogicalId('basic', 'MyQueue');
eventSourceMappingResource = cfTemplate.Resources[queueLogicalId];
});

it('should use functionResponseType', () => {
expect(eventSourceMappingResource.Properties.FunctionResponseTypes).to.include.members([
'ReportBatchItemFailures',
]);
});
});

0 comments on commit 44511f3

Please sign in to comment.