From 0b1e74cff04d3bc6fd5d8637d146d70a7e91313a Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Fri, 5 Mar 2021 08:02:07 +0000 Subject: [PATCH 01/14] feat(aws-lambda): Add tumblingWindowInSeconds to Lambda Event Source --- .../aws-lambda/lib/event-source-mapping.ts | 18 ++++++++++++++++++ .../test/event-source-mapping.test.ts | 15 +++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts index d44ce1cbea1b4..c4574e774a674 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts @@ -101,6 +101,19 @@ export interface EventSourceMappingOptions { * @default - no topic */ readonly kafkaTopic?: string; + + /** + * The size of the tumbling windows to group records sent to DynamoDB or Kinesis + * + * @see https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#services-ddb-windows + * + * Valid Range: + * * Minimum value of 0 + * * Maximum value of 900 + * + * @default - None + */ + readonly tumblingWindowInSeconds?: cdk.Duration; } /** @@ -174,6 +187,10 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp } }); + if (props.tumblingWindowInSeconds && props.tumblingWindowInSeconds.toSeconds() > 900) { + throw new Error(`tumblingWindowInSeconds cannot be over 900 seconds, got ${props.tumblingWindowInSeconds.toSeconds()}`); + } + let destinationConfig; @@ -196,6 +213,7 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp maximumRetryAttempts: props.retryAttempts, parallelizationFactor: props.parallelizationFactor, topics: props.kafkaTopic !== undefined ? [props.kafkaTopic] : undefined, + tumblingWindowInSeconds: props.tumblingWindowInSeconds?.toSeconds(), }); this.eventSourceMappingId = cfnEventSourceMapping.ref; } diff --git a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts index be42067f263f1..1c88c9fc13983 100644 --- a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts @@ -170,4 +170,19 @@ describe('event source mapping', () => { }], }); }); + + test('throws if tumblingWindowInSeconds > 900 seconds', () => { + const stack = new cdk.Stack(); + const fn = new Function(stack, 'fn', { + handler: 'index.handler', + code: Code.fromInline('exports.handler = ${handler.toString()}'), + runtime: Runtime.NODEJS_10_X, + }); + + expect(() => new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + tumblingWindowInSeconds: cdk.Duration.seconds(901), + })).toThrow(/tumblingWindowInSeconds cannot be over 900 seconds/); + }); }); From bb482239fafddcc80c782b1834b615cebb298d62 Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Fri, 5 Mar 2021 17:25:16 +0000 Subject: [PATCH 02/14] feat(aws-lambda-event-sources): Add tumblingWindowInSeconds option Updated DynamoDB and Kinesis events sources, associated tests and README --- .../aws-lambda-event-sources/README.md | 2 + .../aws-lambda-event-sources/lib/stream.ts | 11 ++++ .../test/integ.dynamodb.expected.json | 3 +- .../test/integ.dynamodb.ts | 1 + .../test/integ.kinesis.expected.json | 3 +- .../test/integ.kinesis.ts | 1 + .../test/test.dynamo.ts | 61 +++++++++++++++++++ .../test/test.kinesis.ts | 49 +++++++++++++++ 8 files changed, 129 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-event-sources/README.md b/packages/@aws-cdk/aws-lambda-event-sources/README.md index 5e1578d9aefd4..c2603a6ed09e0 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/README.md +++ b/packages/@aws-cdk/aws-lambda-event-sources/README.md @@ -148,6 +148,7 @@ and add it to your Lambda function. The following parameters will impact Amazon * __parallelizationFactor__: The number of batches to concurrently process on each shard. * __retryAttempts__: The maximum number of times a record should be retried in the event of failure. * __startingPosition__: Will determine where to being consumption, either at the most recent ('LATEST') record or the oldest record ('TRIM_HORIZON'). 'TRIM_HORIZON' will ensure you process all available data, while 'LATEST' will ignore all records that arrived prior to attaching the event source. +* __tumblingWindowInSeconds__: The duration in seconds of a processing window when using streams. * __enabled__: If the DynamoDB Streams event source mapping should be enabled. The default is true. ```ts @@ -192,6 +193,7 @@ behavior: * __parallelizationFactor__: The number of batches to concurrently process on each shard. * __retryAttempts__: The maximum number of times a record should be retried in the event of failure. * __startingPosition__: Will determine where to being consumption, either at the most recent ('LATEST') record or the oldest record ('TRIM_HORIZON'). 'TRIM_HORIZON' will ensure you process all available data, while 'LATEST' will ignore all records that arrived prior to attaching the event source. +* __tumblingWindowInSeconds__: The duration in seconds of a processing window when using streams. * __enabled__: If the DynamoDB Streams event source mapping should be enabled. The default is true. ```ts diff --git a/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts b/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts index d18eaaf3f947c..d0041fc0c2a1e 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts @@ -78,6 +78,16 @@ export interface StreamEventSourceProps { */ readonly maxBatchingWindow?: Duration; + /** + * The size of the tumbling windows to group records sent to DynamoDB or Kinesis + * Valid Range: + * * Minimum value of 0 + * * Maximum value of 900 + * + * @default - None + */ + readonly tumblingWindowInSeconds?: Duration; + /** * If the stream event source mapping should be enabled. * @@ -106,6 +116,7 @@ export abstract class StreamEventSource implements lambda.IEventSource { retryAttempts: this.props.retryAttempts, parallelizationFactor: this.props.parallelizationFactor, onFailure: this.props.onFailure, + tumblingWindowInSeconds: this.props.tumblingWindowInSeconds, enabled: this.props.enabled, }; } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json index 6a16698ea1668..d0bf009c26437 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json @@ -99,7 +99,8 @@ "Ref": "FC4345940" }, "BatchSize": 5, - "StartingPosition": "TRIM_HORIZON" + "StartingPosition": "TRIM_HORIZON", + "TumblingWindowInSeconds": 60 } }, "TD925BC7E": { diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts index ea5089bf98706..b8ea9b36573a5 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts @@ -21,6 +21,7 @@ class DynamoEventSourceTest extends cdk.Stack { fn.addEventSource(new DynamoEventSource(queue, { batchSize: 5, startingPosition: lambda.StartingPosition.TRIM_HORIZON, + tumblingWindowInSeconds: cdk.Duration.seconds(60), })); } } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json index 670d7d05ced59..9e00c27c3d435 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json @@ -106,7 +106,8 @@ "Ref": "FC4345940" }, "BatchSize": 100, - "StartingPosition": "TRIM_HORIZON" + "StartingPosition": "TRIM_HORIZON", + "TumblingWindowInSeconds": 60 } }, "Q63C6E3AB": { diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts index 40dde2a809fc9..c58011006d35e 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts @@ -13,6 +13,7 @@ class KinesisEventSourceTest extends cdk.Stack { fn.addEventSource(new KinesisEventSource(stream, { startingPosition: lambda.StartingPosition.TRIM_HORIZON, + tumblingWindowInSeconds: cdk.Duration.seconds(60), })); } } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts index 41d8535d90235..ffdbb3126733a 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts @@ -76,6 +76,67 @@ export = { test.done(); }, + 'specific tumblingWindowInSeconds'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const fn = new TestFunction(stack, 'Fn'); + const table = new dynamodb.Table(stack, 'T', { + partitionKey: { + name: 'id', + type: dynamodb.AttributeType.STRING, + }, + stream: dynamodb.StreamViewType.NEW_IMAGE, + }); + + // WHEN + fn.addEventSource(new sources.DynamoEventSource(table, { + batchSize: 50, + startingPosition: lambda.StartingPosition.LATEST, + tumblingWindowInSeconds: cdk.Duration.seconds(60), + })); + + // THEN + expect(stack).to(haveResource('AWS::Lambda::EventSourceMapping', { + 'EventSourceArn': { + 'Fn::GetAtt': [ + 'TD925BC7E', + 'StreamArn', + ], + }, + 'FunctionName': { + 'Ref': 'Fn9270CBC0', + }, + 'BatchSize': 50, + 'StartingPosition': 'LATEST', + 'TumblingWindowInSeconds': 60, + })); + + test.done(); + }, + + 'fails if tumblingWindowInSeconds > 900 seconds'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const fn = new TestFunction(stack, 'Fn'); + const table = new dynamodb.Table(stack, 'T', { + partitionKey: { + name: 'id', + type: dynamodb.AttributeType.STRING, + }, + stream: dynamodb.StreamViewType.NEW_IMAGE, + }); + + // THEN + test.throws(() => + fn.addEventSource(new sources.DynamoEventSource(table, { + maxBatchingWindow: cdk.Duration.seconds(60), + startingPosition: lambda.StartingPosition.LATEST, + tumblingWindowInSeconds: cdk.Duration.seconds(901), + })), /tumblingWindowInSeconds cannot be over 900 seconds/); + + test.done(); + }, + 'specific batch size'(test: Test) { // GIVEN const stack = new cdk.Stack(); diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts index 76e437de0ae34..ed1c96102ba26 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts @@ -76,6 +76,55 @@ export = { test.done(); }, + 'specific tumblingWindowInSeconds'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const fn = new TestFunction(stack, 'Fn'); + const stream = new kinesis.Stream(stack, 'S'); + + // WHEN + fn.addEventSource(new sources.KinesisEventSource(stream, { + batchSize: 50, + startingPosition: lambda.StartingPosition.LATEST, + tumblingWindowInSeconds: cdk.Duration.seconds(60), + })); + + // THEN + expect(stack).to(haveResource('AWS::Lambda::EventSourceMapping', { + 'EventSourceArn': { + 'Fn::GetAtt': [ + 'S509448A1', + 'Arn', + ], + }, + 'FunctionName': { + 'Ref': 'Fn9270CBC0', + }, + 'BatchSize': 50, + 'StartingPosition': 'LATEST', + 'TumblingWindowInSeconds': 60, + })); + + test.done(); + }, + + 'fails if tumblingWindowInSeconds > 900 seconds'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const fn = new TestFunction(stack, 'Fn'); + const stream = new kinesis.Stream(stack, 'S'); + + // THEN + test.throws(() => + fn.addEventSource(new sources.KinesisEventSource(stream, { + maxBatchingWindow: cdk.Duration.seconds(60), + startingPosition: lambda.StartingPosition.LATEST, + tumblingWindowInSeconds: cdk.Duration.seconds(901), + })), /tumblingWindowInSeconds cannot be over 900 seconds/); + + test.done(); + }, + 'specific batch size'(test: Test) { // GIVEN const stack = new cdk.Stack(); From bc3249e706aa9a5aad772ba1b450b677ecdd7b81 Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Sun, 7 Mar 2021 20:54:51 +0000 Subject: [PATCH 03/14] feat(aws-lambda-event-sources): Add tumblingWindowInSeconds option Updated DynamoDB and Kinesis events sources, associated tests and README --- .../aws-lambda-event-sources/README.md | 2 + .../aws-lambda-event-sources/lib/stream.ts | 11 ++++ .../test/integ.dynamodb.expected.json | 3 +- .../test/integ.dynamodb.ts | 1 + .../test/integ.kinesis.expected.json | 3 +- .../test/integ.kinesis.ts | 1 + .../test/test.dynamo.ts | 61 +++++++++++++++++++ .../test/test.kinesis.ts | 49 +++++++++++++++ 8 files changed, 129 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-event-sources/README.md b/packages/@aws-cdk/aws-lambda-event-sources/README.md index 5e1578d9aefd4..c2603a6ed09e0 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/README.md +++ b/packages/@aws-cdk/aws-lambda-event-sources/README.md @@ -148,6 +148,7 @@ and add it to your Lambda function. The following parameters will impact Amazon * __parallelizationFactor__: The number of batches to concurrently process on each shard. * __retryAttempts__: The maximum number of times a record should be retried in the event of failure. * __startingPosition__: Will determine where to being consumption, either at the most recent ('LATEST') record or the oldest record ('TRIM_HORIZON'). 'TRIM_HORIZON' will ensure you process all available data, while 'LATEST' will ignore all records that arrived prior to attaching the event source. +* __tumblingWindowInSeconds__: The duration in seconds of a processing window when using streams. * __enabled__: If the DynamoDB Streams event source mapping should be enabled. The default is true. ```ts @@ -192,6 +193,7 @@ behavior: * __parallelizationFactor__: The number of batches to concurrently process on each shard. * __retryAttempts__: The maximum number of times a record should be retried in the event of failure. * __startingPosition__: Will determine where to being consumption, either at the most recent ('LATEST') record or the oldest record ('TRIM_HORIZON'). 'TRIM_HORIZON' will ensure you process all available data, while 'LATEST' will ignore all records that arrived prior to attaching the event source. +* __tumblingWindowInSeconds__: The duration in seconds of a processing window when using streams. * __enabled__: If the DynamoDB Streams event source mapping should be enabled. The default is true. ```ts diff --git a/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts b/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts index d18eaaf3f947c..d0041fc0c2a1e 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts @@ -78,6 +78,16 @@ export interface StreamEventSourceProps { */ readonly maxBatchingWindow?: Duration; + /** + * The size of the tumbling windows to group records sent to DynamoDB or Kinesis + * Valid Range: + * * Minimum value of 0 + * * Maximum value of 900 + * + * @default - None + */ + readonly tumblingWindowInSeconds?: Duration; + /** * If the stream event source mapping should be enabled. * @@ -106,6 +116,7 @@ export abstract class StreamEventSource implements lambda.IEventSource { retryAttempts: this.props.retryAttempts, parallelizationFactor: this.props.parallelizationFactor, onFailure: this.props.onFailure, + tumblingWindowInSeconds: this.props.tumblingWindowInSeconds, enabled: this.props.enabled, }; } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json index 6a16698ea1668..d0bf009c26437 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json @@ -99,7 +99,8 @@ "Ref": "FC4345940" }, "BatchSize": 5, - "StartingPosition": "TRIM_HORIZON" + "StartingPosition": "TRIM_HORIZON", + "TumblingWindowInSeconds": 60 } }, "TD925BC7E": { diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts index ea5089bf98706..b8ea9b36573a5 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts @@ -21,6 +21,7 @@ class DynamoEventSourceTest extends cdk.Stack { fn.addEventSource(new DynamoEventSource(queue, { batchSize: 5, startingPosition: lambda.StartingPosition.TRIM_HORIZON, + tumblingWindowInSeconds: cdk.Duration.seconds(60), })); } } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json index 670d7d05ced59..9e00c27c3d435 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json @@ -106,7 +106,8 @@ "Ref": "FC4345940" }, "BatchSize": 100, - "StartingPosition": "TRIM_HORIZON" + "StartingPosition": "TRIM_HORIZON", + "TumblingWindowInSeconds": 60 } }, "Q63C6E3AB": { diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts index 40dde2a809fc9..c58011006d35e 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts @@ -13,6 +13,7 @@ class KinesisEventSourceTest extends cdk.Stack { fn.addEventSource(new KinesisEventSource(stream, { startingPosition: lambda.StartingPosition.TRIM_HORIZON, + tumblingWindowInSeconds: cdk.Duration.seconds(60), })); } } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts index 41d8535d90235..ffdbb3126733a 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts @@ -76,6 +76,67 @@ export = { test.done(); }, + 'specific tumblingWindowInSeconds'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const fn = new TestFunction(stack, 'Fn'); + const table = new dynamodb.Table(stack, 'T', { + partitionKey: { + name: 'id', + type: dynamodb.AttributeType.STRING, + }, + stream: dynamodb.StreamViewType.NEW_IMAGE, + }); + + // WHEN + fn.addEventSource(new sources.DynamoEventSource(table, { + batchSize: 50, + startingPosition: lambda.StartingPosition.LATEST, + tumblingWindowInSeconds: cdk.Duration.seconds(60), + })); + + // THEN + expect(stack).to(haveResource('AWS::Lambda::EventSourceMapping', { + 'EventSourceArn': { + 'Fn::GetAtt': [ + 'TD925BC7E', + 'StreamArn', + ], + }, + 'FunctionName': { + 'Ref': 'Fn9270CBC0', + }, + 'BatchSize': 50, + 'StartingPosition': 'LATEST', + 'TumblingWindowInSeconds': 60, + })); + + test.done(); + }, + + 'fails if tumblingWindowInSeconds > 900 seconds'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const fn = new TestFunction(stack, 'Fn'); + const table = new dynamodb.Table(stack, 'T', { + partitionKey: { + name: 'id', + type: dynamodb.AttributeType.STRING, + }, + stream: dynamodb.StreamViewType.NEW_IMAGE, + }); + + // THEN + test.throws(() => + fn.addEventSource(new sources.DynamoEventSource(table, { + maxBatchingWindow: cdk.Duration.seconds(60), + startingPosition: lambda.StartingPosition.LATEST, + tumblingWindowInSeconds: cdk.Duration.seconds(901), + })), /tumblingWindowInSeconds cannot be over 900 seconds/); + + test.done(); + }, + 'specific batch size'(test: Test) { // GIVEN const stack = new cdk.Stack(); diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts index 76e437de0ae34..ed1c96102ba26 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts @@ -76,6 +76,55 @@ export = { test.done(); }, + 'specific tumblingWindowInSeconds'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const fn = new TestFunction(stack, 'Fn'); + const stream = new kinesis.Stream(stack, 'S'); + + // WHEN + fn.addEventSource(new sources.KinesisEventSource(stream, { + batchSize: 50, + startingPosition: lambda.StartingPosition.LATEST, + tumblingWindowInSeconds: cdk.Duration.seconds(60), + })); + + // THEN + expect(stack).to(haveResource('AWS::Lambda::EventSourceMapping', { + 'EventSourceArn': { + 'Fn::GetAtt': [ + 'S509448A1', + 'Arn', + ], + }, + 'FunctionName': { + 'Ref': 'Fn9270CBC0', + }, + 'BatchSize': 50, + 'StartingPosition': 'LATEST', + 'TumblingWindowInSeconds': 60, + })); + + test.done(); + }, + + 'fails if tumblingWindowInSeconds > 900 seconds'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const fn = new TestFunction(stack, 'Fn'); + const stream = new kinesis.Stream(stack, 'S'); + + // THEN + test.throws(() => + fn.addEventSource(new sources.KinesisEventSource(stream, { + maxBatchingWindow: cdk.Duration.seconds(60), + startingPosition: lambda.StartingPosition.LATEST, + tumblingWindowInSeconds: cdk.Duration.seconds(901), + })), /tumblingWindowInSeconds cannot be over 900 seconds/); + + test.done(); + }, + 'specific batch size'(test: Test) { // GIVEN const stack = new cdk.Stack(); From 5a09e1e7c419dcdbe8110ebd859a963b9870c7fe Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Sun, 7 Mar 2021 21:02:22 +0000 Subject: [PATCH 04/14] feat(aws-lambda-event-sources): Add tumblingWindowInSeconds option fix naming issue due to failing lint test --- packages/@aws-cdk/aws-lambda-event-sources/README.md | 4 ++-- .../@aws-cdk/aws-lambda-event-sources/lib/stream.ts | 4 ++-- .../aws-lambda-event-sources/test/integ.dynamodb.ts | 2 +- .../aws-lambda-event-sources/test/integ.kinesis.ts | 2 +- .../aws-lambda-event-sources/test/test.dynamo.ts | 10 +++++----- .../aws-lambda-event-sources/test/test.kinesis.ts | 8 ++++---- .../@aws-cdk/aws-lambda/lib/event-source-mapping.ts | 8 ++++---- .../aws-lambda/test/event-source-mapping.test.ts | 6 +++--- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-event-sources/README.md b/packages/@aws-cdk/aws-lambda-event-sources/README.md index c2603a6ed09e0..1e212ae748f98 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/README.md +++ b/packages/@aws-cdk/aws-lambda-event-sources/README.md @@ -148,7 +148,7 @@ and add it to your Lambda function. The following parameters will impact Amazon * __parallelizationFactor__: The number of batches to concurrently process on each shard. * __retryAttempts__: The maximum number of times a record should be retried in the event of failure. * __startingPosition__: Will determine where to being consumption, either at the most recent ('LATEST') record or the oldest record ('TRIM_HORIZON'). 'TRIM_HORIZON' will ensure you process all available data, while 'LATEST' will ignore all records that arrived prior to attaching the event source. -* __tumblingWindowInSeconds__: The duration in seconds of a processing window when using streams. +* __tumblingWindow__: The duration in seconds of a processing window when using streams. * __enabled__: If the DynamoDB Streams event source mapping should be enabled. The default is true. ```ts @@ -193,7 +193,7 @@ behavior: * __parallelizationFactor__: The number of batches to concurrently process on each shard. * __retryAttempts__: The maximum number of times a record should be retried in the event of failure. * __startingPosition__: Will determine where to being consumption, either at the most recent ('LATEST') record or the oldest record ('TRIM_HORIZON'). 'TRIM_HORIZON' will ensure you process all available data, while 'LATEST' will ignore all records that arrived prior to attaching the event source. -* __tumblingWindowInSeconds__: The duration in seconds of a processing window when using streams. +* __tumblingWindow__: The duration in seconds of a processing window when using streams. * __enabled__: If the DynamoDB Streams event source mapping should be enabled. The default is true. ```ts diff --git a/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts b/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts index d0041fc0c2a1e..2966cc79f9984 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts @@ -86,7 +86,7 @@ export interface StreamEventSourceProps { * * @default - None */ - readonly tumblingWindowInSeconds?: Duration; + readonly tumblingWindow?: Duration; /** * If the stream event source mapping should be enabled. @@ -116,7 +116,7 @@ export abstract class StreamEventSource implements lambda.IEventSource { retryAttempts: this.props.retryAttempts, parallelizationFactor: this.props.parallelizationFactor, onFailure: this.props.onFailure, - tumblingWindowInSeconds: this.props.tumblingWindowInSeconds, + tumblingWindow: this.props.tumblingWindow, enabled: this.props.enabled, }; } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts index b8ea9b36573a5..aa4f6f244ee94 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.ts @@ -21,7 +21,7 @@ class DynamoEventSourceTest extends cdk.Stack { fn.addEventSource(new DynamoEventSource(queue, { batchSize: 5, startingPosition: lambda.StartingPosition.TRIM_HORIZON, - tumblingWindowInSeconds: cdk.Duration.seconds(60), + tumblingWindow: cdk.Duration.seconds(60), })); } } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts index c58011006d35e..212c66e44ec11 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.ts @@ -13,7 +13,7 @@ class KinesisEventSourceTest extends cdk.Stack { fn.addEventSource(new KinesisEventSource(stream, { startingPosition: lambda.StartingPosition.TRIM_HORIZON, - tumblingWindowInSeconds: cdk.Duration.seconds(60), + tumblingWindow: cdk.Duration.seconds(60), })); } } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts index ffdbb3126733a..70d09f2425eae 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts @@ -76,7 +76,7 @@ export = { test.done(); }, - 'specific tumblingWindowInSeconds'(test: Test) { + 'specific tumblingWindow'(test: Test) { // GIVEN const stack = new cdk.Stack(); const fn = new TestFunction(stack, 'Fn'); @@ -92,7 +92,7 @@ export = { fn.addEventSource(new sources.DynamoEventSource(table, { batchSize: 50, startingPosition: lambda.StartingPosition.LATEST, - tumblingWindowInSeconds: cdk.Duration.seconds(60), + tumblingWindow: cdk.Duration.seconds(60), })); // THEN @@ -114,7 +114,7 @@ export = { test.done(); }, - 'fails if tumblingWindowInSeconds > 900 seconds'(test: Test) { + 'fails if tumblingWindow > 900 seconds'(test: Test) { // GIVEN const stack = new cdk.Stack(); const fn = new TestFunction(stack, 'Fn'); @@ -131,8 +131,8 @@ export = { fn.addEventSource(new sources.DynamoEventSource(table, { maxBatchingWindow: cdk.Duration.seconds(60), startingPosition: lambda.StartingPosition.LATEST, - tumblingWindowInSeconds: cdk.Duration.seconds(901), - })), /tumblingWindowInSeconds cannot be over 900 seconds/); + tumblingWindow: cdk.Duration.seconds(901), + })), /tumblingWindow cannot be over 900 seconds/); test.done(); }, diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts index ed1c96102ba26..aceb80283d062 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts @@ -86,7 +86,7 @@ export = { fn.addEventSource(new sources.KinesisEventSource(stream, { batchSize: 50, startingPosition: lambda.StartingPosition.LATEST, - tumblingWindowInSeconds: cdk.Duration.seconds(60), + tumblingWindow: cdk.Duration.seconds(60), })); // THEN @@ -108,7 +108,7 @@ export = { test.done(); }, - 'fails if tumblingWindowInSeconds > 900 seconds'(test: Test) { + 'fails if tumblingWindow > 900 seconds'(test: Test) { // GIVEN const stack = new cdk.Stack(); const fn = new TestFunction(stack, 'Fn'); @@ -119,8 +119,8 @@ export = { fn.addEventSource(new sources.KinesisEventSource(stream, { maxBatchingWindow: cdk.Duration.seconds(60), startingPosition: lambda.StartingPosition.LATEST, - tumblingWindowInSeconds: cdk.Duration.seconds(901), - })), /tumblingWindowInSeconds cannot be over 900 seconds/); + tumblingWindow: cdk.Duration.seconds(901), + })), /tumblingWindow cannot be over 900 seconds/); test.done(); }, diff --git a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts index c4574e774a674..929e57dbe9481 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts @@ -113,7 +113,7 @@ export interface EventSourceMappingOptions { * * @default - None */ - readonly tumblingWindowInSeconds?: cdk.Duration; + readonly tumblingWindow?: cdk.Duration; } /** @@ -187,8 +187,8 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp } }); - if (props.tumblingWindowInSeconds && props.tumblingWindowInSeconds.toSeconds() > 900) { - throw new Error(`tumblingWindowInSeconds cannot be over 900 seconds, got ${props.tumblingWindowInSeconds.toSeconds()}`); + if (props.tumblingWindow && props.tumblingWindow.toSeconds() > 900) { + throw new Error(`tumblingWindow cannot be over 900 seconds, got ${props.tumblingWindow.toSeconds()}`); } @@ -213,7 +213,7 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp maximumRetryAttempts: props.retryAttempts, parallelizationFactor: props.parallelizationFactor, topics: props.kafkaTopic !== undefined ? [props.kafkaTopic] : undefined, - tumblingWindowInSeconds: props.tumblingWindowInSeconds?.toSeconds(), + tumblingWindowInSeconds: props.tumblingWindow?.toSeconds(), }); this.eventSourceMappingId = cfnEventSourceMapping.ref; } diff --git a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts index 1c88c9fc13983..4de6214dd3136 100644 --- a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts @@ -171,7 +171,7 @@ describe('event source mapping', () => { }); }); - test('throws if tumblingWindowInSeconds > 900 seconds', () => { + test('throws if tumblingWindow > 900 seconds', () => { const stack = new cdk.Stack(); const fn = new Function(stack, 'fn', { handler: 'index.handler', @@ -182,7 +182,7 @@ describe('event source mapping', () => { expect(() => new EventSourceMapping(stack, 'test', { target: fn, eventSourceArn: '', - tumblingWindowInSeconds: cdk.Duration.seconds(901), - })).toThrow(/tumblingWindowInSeconds cannot be over 900 seconds/); + tumblingWindow: cdk.Duration.seconds(901), + })).toThrow(/tumblingWindow cannot be over 900 seconds/); }); }); From 0f3c1351340a6cae625f719ddaecf38688f283aa Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Tue, 23 Mar 2021 08:40:58 +1300 Subject: [PATCH 05/14] Update packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts Co-authored-by: Niranjan Jayakar --- packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts index 929e57dbe9481..4bf5a618c09db 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts @@ -187,7 +187,7 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp } }); - if (props.tumblingWindow && props.tumblingWindow.toSeconds() > 900) { + if (props.tumblingWindow && !props.tumblingWindow.isUnresolved() && props.tumblingWindow.toSeconds() > 900) { throw new Error(`tumblingWindow cannot be over 900 seconds, got ${props.tumblingWindow.toSeconds()}`); } From 366df98827968c9ede6bac744689b7b04ab32427 Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Tue, 23 Mar 2021 08:41:54 +1300 Subject: [PATCH 06/14] Update packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts Co-authored-by: Niranjan Jayakar --- .../aws-lambda-event-sources/test/test.dynamo.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts index 70d09f2425eae..074a4a74d5d16 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts @@ -97,18 +97,7 @@ export = { // THEN expect(stack).to(haveResource('AWS::Lambda::EventSourceMapping', { - 'EventSourceArn': { - 'Fn::GetAtt': [ - 'TD925BC7E', - 'StreamArn', - ], - }, - 'FunctionName': { - 'Ref': 'Fn9270CBC0', - }, - 'BatchSize': 50, - 'StartingPosition': 'LATEST', - 'TumblingWindowInSeconds': 60, + TumblingWindowInSeconds: 60, })); test.done(); From 40a6e736f8df8020cd01fe8e944236ae6f3d8dd0 Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Mon, 22 Mar 2021 20:05:48 +0000 Subject: [PATCH 07/14] feat(aws-lambda):tumbling window --- .../test/test.dynamo.ts | 23 ------------------- .../test/test.kinesis.ts | 17 -------------- .../test/event-source-mapping.test.ts | 15 ++++++++++++ 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts index 074a4a74d5d16..7793cf54b9cc0 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.dynamo.ts @@ -103,29 +103,6 @@ export = { test.done(); }, - 'fails if tumblingWindow > 900 seconds'(test: Test) { - // GIVEN - const stack = new cdk.Stack(); - const fn = new TestFunction(stack, 'Fn'); - const table = new dynamodb.Table(stack, 'T', { - partitionKey: { - name: 'id', - type: dynamodb.AttributeType.STRING, - }, - stream: dynamodb.StreamViewType.NEW_IMAGE, - }); - - // THEN - test.throws(() => - fn.addEventSource(new sources.DynamoEventSource(table, { - maxBatchingWindow: cdk.Duration.seconds(60), - startingPosition: lambda.StartingPosition.LATEST, - tumblingWindow: cdk.Duration.seconds(901), - })), /tumblingWindow cannot be over 900 seconds/); - - test.done(); - }, - 'specific batch size'(test: Test) { // GIVEN const stack = new cdk.Stack(); diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts index aceb80283d062..c36ecba6156ce 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test.kinesis.ts @@ -108,23 +108,6 @@ export = { test.done(); }, - 'fails if tumblingWindow > 900 seconds'(test: Test) { - // GIVEN - const stack = new cdk.Stack(); - const fn = new TestFunction(stack, 'Fn'); - const stream = new kinesis.Stream(stack, 'S'); - - // THEN - test.throws(() => - fn.addEventSource(new sources.KinesisEventSource(stream, { - maxBatchingWindow: cdk.Duration.seconds(60), - startingPosition: lambda.StartingPosition.LATEST, - tumblingWindow: cdk.Duration.seconds(901), - })), /tumblingWindow cannot be over 900 seconds/); - - test.done(); - }, - 'specific batch size'(test: Test) { // GIVEN const stack = new cdk.Stack(); diff --git a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts index 4de6214dd3136..618424b53e6a9 100644 --- a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts @@ -185,4 +185,19 @@ describe('event source mapping', () => { tumblingWindow: cdk.Duration.seconds(901), })).toThrow(/tumblingWindow cannot be over 900 seconds/); }); + + test('accepts if tumblingWindow is a token', () => { + const stack = new cdk.Stack(); + const fn = new Function(stack, 'fn', { + handler: 'index.handler', + code: Code.fromInline('exports.handler = ${handler.toString()}'), + runtime: Runtime.NODEJS_10_X, + }); + + new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + tumblingWindow: cdk.Lazy.number({ produce: () => 60 }), + }); + }); }); From 870cf07e826810abe97c87bf0bf67f5a63a3fbfd Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Wed, 24 Mar 2021 04:55:51 +0000 Subject: [PATCH 08/14] feat(aws-lambda):tumbling window --- packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts index 4bf5a618c09db..c50cc340fead7 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts @@ -107,9 +107,7 @@ export interface EventSourceMappingOptions { * * @see https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#services-ddb-windows * - * Valid Range: - * * Minimum value of 0 - * * Maximum value of 900 + * Valid Range: 0 - 15 minutes * * @default - None */ @@ -187,7 +185,7 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp } }); - if (props.tumblingWindow && !props.tumblingWindow.isUnresolved() && props.tumblingWindow.toSeconds() > 900) { + if (props.tumblingWindow && !cdk.Token.isUnresolved(props.tumblingWindow) && props.tumblingWindow.toSeconds() > 900) { throw new Error(`tumblingWindow cannot be over 900 seconds, got ${props.tumblingWindow.toSeconds()}`); } From 6b2cad621c94eec0c88455109d73687bda6b4612 Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Wed, 24 Mar 2021 17:59:18 +1300 Subject: [PATCH 09/14] feat(aws-lambda):tumbling window --- packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts index 4bf5a618c09db..c8756480de324 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts @@ -107,9 +107,7 @@ export interface EventSourceMappingOptions { * * @see https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#services-ddb-windows * - * Valid Range: - * * Minimum value of 0 - * * Maximum value of 900 + * Valid Range: 0 - 15 minutes * * @default - None */ From 9587fa55e8020794dce2d766ddb0ec3660b7eb6e Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Wed, 24 Mar 2021 18:00:40 +1300 Subject: [PATCH 10/14] feat(aws-lambda):tumbling window --- packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts b/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts index 2966cc79f9984..772d350bc6479 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/lib/stream.ts @@ -80,9 +80,7 @@ export interface StreamEventSourceProps { /** * The size of the tumbling windows to group records sent to DynamoDB or Kinesis - * Valid Range: - * * Minimum value of 0 - * * Maximum value of 900 + * Valid Range: 0 - 15 minutes * * @default - None */ From 918013726000130a370ae9576d80587a86082869 Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Wed, 24 Mar 2021 18:02:11 +1300 Subject: [PATCH 11/14] feat(aws-lambda):tumbling window --- packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts index c8756480de324..c50cc340fead7 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts @@ -185,7 +185,7 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp } }); - if (props.tumblingWindow && !props.tumblingWindow.isUnresolved() && props.tumblingWindow.toSeconds() > 900) { + if (props.tumblingWindow && !cdk.Token.isUnresolved(props.tumblingWindow) && props.tumblingWindow.toSeconds() > 900) { throw new Error(`tumblingWindow cannot be over 900 seconds, got ${props.tumblingWindow.toSeconds()}`); } From 5fc02f33f5ab6f286ebb2c7909ed3a4ae344cd38 Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Wed, 24 Mar 2021 08:48:02 +0000 Subject: [PATCH 12/14] feat(aws-lambda):tumbling window --- .../@aws-cdk/aws-lambda/test/event-source-mapping.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts index 618424b53e6a9..409565fc34d7f 100644 --- a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts @@ -186,18 +186,19 @@ describe('event source mapping', () => { })).toThrow(/tumblingWindow cannot be over 900 seconds/); }); - test('accepts if tumblingWindow is a token', () => { + test('accepts if tumblingWindow is a token', () => { const stack = new cdk.Stack(); const fn = new Function(stack, 'fn', { handler: 'index.handler', code: Code.fromInline('exports.handler = ${handler.toString()}'), runtime: Runtime.NODEJS_10_X, }); + const lazyDuration = cdk.Duration.seconds(cdk.Lazy.number({ produce: () => 60 })); new EventSourceMapping(stack, 'test', { target: fn, eventSourceArn: '', - tumblingWindow: cdk.Lazy.number({ produce: () => 60 }), + tumblingWindow: lazyDuration, }); }); }); From adc53c4c3c2fa35f70486b9d47ee6f8d1782a96d Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Fri, 26 Mar 2021 01:55:18 +0000 Subject: [PATCH 13/14] feat(aws-lambda):tumbling window --- .../test/integ.dynamodb.expected.json | 5 -- .../test/integ.kinesis.expected.json | 5 -- .../aws-lambda/lib/event-source-mapping.ts | 2 +- .../test/event-source-mapping.test.ts | 55 ++++++++++--------- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json index cbdd08dadf631..0f3557acedc33 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.dynamodb.expected.json @@ -99,11 +99,6 @@ "StreamArn" ] }, - "FunctionName": { - "Ref": "FC4345940" - }, - "BatchSize": 5, - "StartingPosition": "TRIM_HORIZON", "TumblingWindowInSeconds": 60, "StartingPosition": "TRIM_HORIZON" } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json index fcbf56e3425e6..aafb84ca19c72 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.kinesis.expected.json @@ -106,11 +106,6 @@ "Arn" ] }, - "FunctionName": { - "Ref": "FC4345940" - }, - "BatchSize": 100, - "StartingPosition": "TRIM_HORIZON", "TumblingWindowInSeconds": 60, "StartingPosition": "TRIM_HORIZON" } diff --git a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts index 0df680020a24e..924868449a973 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts @@ -178,7 +178,7 @@ export interface EventSourceMappingOptions { * @default - None */ readonly tumblingWindow?: cdk.Duration; - + /** * A list of host and port pairs that are the addresses of the Kafka brokers in a self managed "bootstrap" Kafka cluster * that a Kafka client connects to initially to bootstrap itself. diff --git a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts index 94a5bdd69bcf4..d20723eead6cc 100644 --- a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts @@ -261,34 +261,35 @@ describe('event source mapping', () => { SelfManagedEventSource: { Endpoints: { KafkaBootstrapServers: kafkaBootstrapServers } }, }); - test('throws if tumblingWindow > 900 seconds', () => { - const stack = new cdk.Stack(); - const fn = new Function(stack, 'fn', { - handler: 'index.handler', - code: Code.fromInline('exports.handler = ${handler.toString()}'), - runtime: Runtime.NODEJS_10_X, - }); - - expect(() => new EventSourceMapping(stack, 'test', { - target: fn, - eventSourceArn: '', - tumblingWindow: cdk.Duration.seconds(901), - })).toThrow(/tumblingWindow cannot be over 900 seconds/); - }); - - test('accepts if tumblingWindow is a token', () => { - const stack = new cdk.Stack(); - const fn = new Function(stack, 'fn', { - handler: 'index.handler', - code: Code.fromInline('exports.handler = ${handler.toString()}'), - runtime: Runtime.NODEJS_10_X, + test('throws if tumblingWindow > 900 seconds', () => { + const stack = new cdk.Stack(); + const fn = new Function(stack, 'fn', { + handler: 'index.handler', + code: Code.fromInline('exports.handler = ${handler.toString()}'), + runtime: Runtime.NODEJS_10_X, + }); + + expect(() => new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + tumblingWindow: cdk.Duration.seconds(901), + })).toThrow(/tumblingWindow cannot be over 900 seconds/); }); - const lazyDuration = cdk.Duration.seconds(cdk.Lazy.number({ produce: () => 60 })); - new EventSourceMapping(stack, 'test', { - target: fn, - eventSourceArn: '', - tumblingWindow: lazyDuration, + test('accepts if tumblingWindow is a token', () => { + const stack = new cdk.Stack(); + const fn = new Function(stack, 'fn', { + handler: 'index.handler', + code: Code.fromInline('exports.handler = ${handler.toString()}'), + runtime: Runtime.NODEJS_10_X, + }); + const lazyDuration = cdk.Duration.seconds(cdk.Lazy.number({ produce: () => 60 })); + + new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + tumblingWindow: lazyDuration, + }); }); }); -}); +}); \ No newline at end of file From 28f1297ce7ab8649deaa5436eb540836b1813bcb Mon Sep 17 00:00:00 2001 From: Matt Simpson Date: Fri, 26 Mar 2021 03:27:46 +0000 Subject: [PATCH 14/14] feat(aws-lambda):tumbling windows --- .../test/event-source-mapping.test.ts | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts index d20723eead6cc..92e60d3959f29 100644 --- a/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts @@ -260,36 +260,36 @@ describe('event source mapping', () => { expect(stack).toHaveResourceLike('AWS::Lambda::EventSourceMapping', { SelfManagedEventSource: { Endpoints: { KafkaBootstrapServers: kafkaBootstrapServers } }, }); + }); - test('throws if tumblingWindow > 900 seconds', () => { - const stack = new cdk.Stack(); - const fn = new Function(stack, 'fn', { - handler: 'index.handler', - code: Code.fromInline('exports.handler = ${handler.toString()}'), - runtime: Runtime.NODEJS_10_X, - }); - - expect(() => new EventSourceMapping(stack, 'test', { - target: fn, - eventSourceArn: '', - tumblingWindow: cdk.Duration.seconds(901), - })).toThrow(/tumblingWindow cannot be over 900 seconds/); + test('throws if tumblingWindow > 900 seconds', () => { + const stack = new cdk.Stack(); + const fn = new Function(stack, 'fn', { + handler: 'index.handler', + code: Code.fromInline('exports.handler = ${handler.toString()}'), + runtime: Runtime.NODEJS_10_X, }); - test('accepts if tumblingWindow is a token', () => { - const stack = new cdk.Stack(); - const fn = new Function(stack, 'fn', { - handler: 'index.handler', - code: Code.fromInline('exports.handler = ${handler.toString()}'), - runtime: Runtime.NODEJS_10_X, - }); - const lazyDuration = cdk.Duration.seconds(cdk.Lazy.number({ produce: () => 60 })); - - new EventSourceMapping(stack, 'test', { - target: fn, - eventSourceArn: '', - tumblingWindow: lazyDuration, - }); + expect(() => new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + tumblingWindow: cdk.Duration.seconds(901), + })).toThrow(/tumblingWindow cannot be over 900 seconds/); + }); + + test('accepts if tumblingWindow is a token', () => { + const stack = new cdk.Stack(); + const fn = new Function(stack, 'fn', { + handler: 'index.handler', + code: Code.fromInline('exports.handler = ${handler.toString()}'), + runtime: Runtime.NODEJS_10_X, + }); + const lazyDuration = cdk.Duration.seconds(cdk.Lazy.number({ produce: () => 60 })); + + new EventSourceMapping(stack, 'test', { + target: fn, + eventSourceArn: '', + tumblingWindow: lazyDuration, }); }); }); \ No newline at end of file