Skip to content

Commit 5ddaef4

Browse files
authored
fix(aws-lambda-event-sources): unsupported properties for SelfManagedKafkaEventSource and ManagedKafkaEventSource (#17965)
This PR fixes a bug in the CDK where some `kafkaEventSource` properties are actually unsupported. These properties exist only for kinesis and dynamodb streams. The existing KafkaEventSourceProps Interface erroneously extends an interface that includes kinesis and dynamodb specific properties. This PR separates these properties into a `Base` interface with shared stream properties for all 3, as well as an interface for `kinesis` and `dynamodb` specific properties. Unit testing unavailable because the scope of the PR is to remove properties. It is enough to ensure that current tests still succeed. We are allowing the breaking changes specified in `allowed-breaking-changes.txt` because they never worked in the first place. Fixes #17934. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4fb0309 commit 5ddaef4

File tree

3 files changed

+59
-30
lines changed

3 files changed

+59
-30
lines changed

allowed-breaking-changes.txt

+23
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,26 @@ incompatible-argument:@aws-cdk/aws-autoscaling-hooktargets.FunctionHook.bind
9393
incompatible-argument:@aws-cdk/aws-autoscaling-hooktargets.QueueHook.bind
9494
incompatible-argument:@aws-cdk/aws-autoscaling-hooktargets.TopicHook.bind
9595
incompatible-argument:@aws-cdk/aws-autoscaling.ILifecycleHookTarget.bind
96+
97+
# removed properties from kafka eventsources as they are not supported
98+
removed:@aws-cdk/aws-lambda-event-sources.KafkaEventSourceProps.bisectBatchOnError
99+
removed:@aws-cdk/aws-lambda-event-sources.KafkaEventSourceProps.maxRecordAge
100+
removed:@aws-cdk/aws-lambda-event-sources.KafkaEventSourceProps.parallelizationFactor
101+
removed:@aws-cdk/aws-lambda-event-sources.KafkaEventSourceProps.reportBatchItemFailures
102+
removed:@aws-cdk/aws-lambda-event-sources.KafkaEventSourceProps.retryAttempts
103+
removed:@aws-cdk/aws-lambda-event-sources.KafkaEventSourceProps.tumblingWindow
104+
removed:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps.bisectBatchOnError
105+
removed:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps.maxRecordAge
106+
removed:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps.parallelizationFactor
107+
removed:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps.reportBatchItemFailures
108+
removed:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps.retryAttempts
109+
removed:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps.tumblingWindow
110+
removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.bisectBatchOnError
111+
removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.maxRecordAge
112+
removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.parallelizationFactor
113+
removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.reportBatchItemFailures
114+
removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.retryAttempts
115+
removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.tumblingWindow
116+
base-types:@aws-cdk/aws-lambda-event-sources.KafkaEventSourceProps
117+
base-types:@aws-cdk/aws-lambda-event-sources.ManagedKafkaEventSourceProps
118+
base-types:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as iam from '@aws-cdk/aws-iam';
44
import * as lambda from '@aws-cdk/aws-lambda';
55
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
66
import { Stack, Names } from '@aws-cdk/core';
7-
import { StreamEventSource, StreamEventSourceProps } from './stream';
7+
import { StreamEventSource, BaseStreamEventSourceProps } from './stream';
88

99
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
1010
// eslint-disable-next-line no-duplicate-imports, import/order
@@ -13,7 +13,7 @@ import { Construct } from '@aws-cdk/core';
1313
/**
1414
* Properties for a Kafka event source
1515
*/
16-
export interface KafkaEventSourceProps extends StreamEventSourceProps {
16+
export interface KafkaEventSourceProps extends BaseStreamEventSourceProps{
1717
/**
1818
* The Kafka topic to subscribe to
1919
*/

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

+34-28
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Duration } from '@aws-cdk/core';
55
* The set of properties for event sources that follow the streaming model,
66
* such as, Dynamo, Kinesis and Kafka.
77
*/
8-
export interface StreamEventSourceProps {
8+
export interface BaseStreamEventSourceProps{
99
/**
1010
* The largest number of records that AWS Lambda will retrieve from your event
1111
* source at the time of invoking your function. Your function receives an
@@ -15,25 +15,51 @@ export interface StreamEventSourceProps {
1515
* * Minimum value of 1
1616
* * Maximum value of:
1717
* * 1000 for {@link DynamoEventSource}
18-
* * 10000 for {@link KinesisEventSource}
18+
* * 10000 for {@link KinesisEventSource}, {@link ManagedKafkaEventSource} and {@link SelfManagedKafkaEventSource}
1919
*
2020
* @default 100
2121
*/
2222
readonly batchSize?: number;
2323

2424
/**
25-
* If the function returns an error, split the batch in two and retry.
25+
* An Amazon SQS queue or Amazon SNS topic destination for discarded records.
2626
*
27-
* @default false
27+
* @default discarded records are ignored
2828
*/
29-
readonly bisectBatchOnError?: boolean;
29+
readonly onFailure?: lambda.IEventSourceDlq;
3030

3131
/**
32-
* An Amazon SQS queue or Amazon SNS topic destination for discarded records.
32+
* Where to begin consuming the stream.
33+
*/
34+
readonly startingPosition: lambda.StartingPosition;
35+
36+
/**
37+
* The maximum amount of time to gather records before invoking the function.
38+
* Maximum of Duration.minutes(5)
3339
*
34-
* @default discarded records are ignored
40+
* @default Duration.seconds(0)
3541
*/
36-
readonly onFailure?: lambda.IEventSourceDlq;
42+
readonly maxBatchingWindow?: Duration;
43+
44+
/**
45+
* If the stream event source mapping should be enabled.
46+
*
47+
* @default true
48+
*/
49+
readonly enabled?: boolean;
50+
}
51+
52+
/**
53+
* The set of properties for event sources that follow the streaming model,
54+
* such as, Dynamo, Kinesis.
55+
*/
56+
export interface StreamEventSourceProps extends BaseStreamEventSourceProps {
57+
/**
58+
* If the function returns an error, split the batch in two and retry.
59+
*
60+
* @default false
61+
*/
62+
readonly bisectBatchOnError?: boolean;
3763

3864
/**
3965
* The maximum age of a record that Lambda sends to a function for processing.
@@ -65,11 +91,6 @@ export interface StreamEventSourceProps {
6591
*/
6692
readonly parallelizationFactor?: number;
6793

68-
/**
69-
* Where to begin consuming the stream.
70-
*/
71-
readonly startingPosition: lambda.StartingPosition;
72-
7394
/**
7495
* Allow functions to return partially successful responses for a batch of records.
7596
*
@@ -79,28 +100,13 @@ export interface StreamEventSourceProps {
79100
*/
80101
readonly reportBatchItemFailures?: boolean;
81102

82-
/**
83-
* The maximum amount of time to gather records before invoking the function.
84-
* Maximum of Duration.minutes(5)
85-
*
86-
* @default Duration.seconds(0)
87-
*/
88-
readonly maxBatchingWindow?: Duration;
89-
90103
/**
91104
* The size of the tumbling windows to group records sent to DynamoDB or Kinesis
92105
* Valid Range: 0 - 15 minutes
93106
*
94107
* @default - None
95108
*/
96109
readonly tumblingWindow?: Duration;
97-
98-
/**
99-
* If the stream event source mapping should be enabled.
100-
*
101-
* @default true
102-
*/
103-
readonly enabled?: boolean;
104110
}
105111

106112
/**

0 commit comments

Comments
 (0)