Skip to content

Commit deaefe6

Browse files
author
Sean Dawson
authored
Merge pull request #261 from agiledigital-labs/master
feat: pass through batching window parameter
2 parents 81ca46f + 83e2922 commit deaefe6

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ functions:
4848
name: TestEvent # Required - choose a name prefix for the event queue
4949
topicArn: !Ref Topic # Required - SNS topic to subscribe to
5050
batchSize: 2 # Optional - default value is 10
51+
maximumBatchingWindowInSeconds: 10 # optional - default is 0 (no batch window)
5152
maxRetryCount: 2 # Optional - default value is 5
5253
kmsMasterKeyId: alias/aws/sqs # optional - default is none (no encryption)
5354
kmsDataKeyReusePeriodSeconds: 600 # optional - AWS default is 300 seconds

example-service/serverless.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ functions:
1717
name: ResourcePrefix
1818
topicArn: ${self:custom.topicArn}
1919
batchSize: 2
20+
maximumBatchingWindowInSeconds: 30
2021
maxRetryCount: 2
2122
kmsMasterKeyId: alias/aws/sqs
2223
kmsDataKeyReusePeriodSeconds: 600

lib/__snapshots__/serverless-sns-sqs-lambda.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Object {
4747
"Arn",
4848
],
4949
},
50+
"MaximumBatchingWindowInSeconds": 99,
5051
},
5152
"Type": "AWS::Lambda::EventSourceMapping",
5253
},
@@ -95,6 +96,7 @@ Object {
9596
"Arn",
9697
],
9798
},
99+
"MaximumBatchingWindowInSeconds": 0,
98100
},
99101
"Type": "AWS::Lambda::EventSourceMapping",
100102
},
@@ -143,6 +145,7 @@ Object {
143145
"Arn",
144146
],
145147
},
148+
"MaximumBatchingWindowInSeconds": 0,
146149
},
147150
"Type": "AWS::Lambda::EventSourceMapping",
148151
},

lib/serverless-sns-sqs-lambda.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe("Test Serverless SNS SQS Lambda", () => {
8888
name: "some name",
8989
topicArn: "some arn",
9090
batchSize: 7,
91+
maximumBatchingWindowInSeconds: 99,
9192
prefix: "some prefix",
9293
maxRetryCount: 4,
9394
kmsMasterKeyId: "some key",

lib/serverless-sns-sqs-lambda.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Config = {
1313
funcName: string;
1414
prefix: string;
1515
batchSize: number;
16+
maximumBatchingWindowInSeconds: number;
1617
maxRetryCount: number;
1718
kmsMasterKeyId: string;
1819
kmsDataKeyReusePeriodSeconds: number;
@@ -61,16 +62,19 @@ const pascalCase = camelCase =>
6162
* handler: handler.handler
6263
* events:
6364
* - snsSqs:
64-
* name: Event
65-
* topicArn: !Ref TopicArn
66-
* maxRetryCount: 2 # optional - default is 5
67-
* batchSize: 1 # optional - default is 10
68-
* kmsMasterKeyId: alias/aws/sqs # optional - default is none (no encryption)
69-
* kmsDataKeyReusePeriodSeconds: 600 # optional - AWS default is 300 seconds
70-
* filterPolicy:KmsMasterKeyId
71-
* pet:
72-
* - dog
73-
* - cat
65+
* name: ResourcePrefix
66+
* topicArn: ${self:custom.topicArn}
67+
* batchSize: 2
68+
* maximumBatchingWindowInSeconds: 30
69+
* maxRetryCount: 2
70+
* kmsMasterKeyId: alias/aws/sqs
71+
* kmsDataKeyReusePeriodSeconds: 600
72+
* visibilityTimeout: 120
73+
* rawMessageDelivery: true
74+
* filterPolicy:
75+
* pet:
76+
* - dog
77+
* - cat
7478
*/
7579
export default class ServerlessSnsSqsLambda {
7680
serverless: any;
@@ -185,6 +189,7 @@ Usage
185189
prefix: some-prefix # optional - default is \`\${this.serviceName}-\${stage}-\${funcNamePascalCase}\`
186190
maxRetryCount: 2 # optional - default is 5
187191
batchSize: 1 # optional - default is 10
192+
batchWindow: 10 # optional - default is 0 (no batch window)
188193
kmsMasterKeyId: alias/aws/sqs # optional - default is none (no encryption)
189194
kmsDataKeyReusePeriodSeconds: 600 # optional - AWS default is 300 seconds
190195
deadLetterMessageRetentionPeriodSeconds: 1209600 # optional - AWS default is 345600 secs (4 days)
@@ -230,14 +235,15 @@ Usage
230235
*/
231236
addEventSourceMapping(
232237
template,
233-
{ funcName, name, batchSize, enabled }: Config
238+
{ funcName, name, batchSize, maximumBatchingWindowInSeconds, enabled }: Config
234239
) {
235240
const enabledWithDefault = enabled !== undefined ? enabled : true;
236241
template.Resources[`${funcName}EventSourceMappingSQS${name}Queue`] = {
237242
Type: "AWS::Lambda::EventSourceMapping",
238243
DependsOn: "IamRoleLambdaExecution",
239244
Properties: {
240245
BatchSize: batchSize,
246+
MaximumBatchingWindowInSeconds: maximumBatchingWindowInSeconds !== undefined ? maximumBatchingWindowInSeconds : 0,
241247
EventSourceArn: { "Fn::GetAtt": [`${name}Queue`, "Arn"] },
242248
FunctionName: { "Fn::GetAtt": [`${funcName}LambdaFunction`, "Arn"] },
243249
Enabled: enabledWithDefault ? "True" : "False"

0 commit comments

Comments
 (0)