Skip to content

Commit 320cc25

Browse files
authored
fix(lambda): allow tokens in kafka consumer group id (#22993)
- fix(lambda): allow token kafka consumer group id - fix(lambda): typo in kafka consumer group id validation Fixes: #22932 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d308bc5 commit 320cc25

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,18 @@ export class EventSourceMapping extends cdk.Resource implements IEventSourceMapp
382382
}
383383

384384
private validateKafkaConsumerGroupIdOrThrow(kafkaConsumerGroupId: string) {
385+
if (cdk.Token.isUnresolved(kafkaConsumerGroupId)) {
386+
return;
387+
}
388+
385389
if (kafkaConsumerGroupId.length > 200 ||kafkaConsumerGroupId.length < 1) {
386390
throw new Error('kafkaConsumerGroupId must be a valid string between 1 and 200 characters');
387391
}
388392

389393
const regex = new RegExp(/[a-zA-Z0-9-\/*:_+=.@-]*/);
390394
const patternMatch = regex.exec(kafkaConsumerGroupId);
391395
if (patternMatch === null || patternMatch[0] !== kafkaConsumerGroupId) {
392-
throw new Error('kafkaConsumerGroupId contain ivalid characters. Allowed values are "[a-zA-Z0-9-\/*:_+=.@-]"');
396+
throw new Error('kafkaConsumerGroupId contains invalid characters. Allowed values are "[a-zA-Z0-9-\/*:_+=.@-]"');
393397
}
394398
}
395399
}

packages/@aws-cdk/aws-lambda/test/event-source-mapping.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('event source mapping', () => {
159159
eventSourceArn: 'arn:aws:kafka:us-east-1:123456789012:cluster/vpc-2priv-2pub/751d2973-a626-431c-9d4e-d7975eb44dd7-2',
160160
kafkaConsumerGroupId: 'some invalid',
161161
target: fn,
162-
})).toThrow('kafkaConsumerGroupId contain ivalid characters. Allowed values are "[a-zA-Z0-9-\/*:_+=.@-]"');
162+
})).toThrow('kafkaConsumerGroupId contains invalid characters. Allowed values are "[a-zA-Z0-9-\/*:_+=.@-]"');
163163
});
164164

165165
test('throws if kafkaConsumerGroupId is too long', () => {
@@ -178,6 +178,14 @@ describe('event source mapping', () => {
178178
})).not.toThrow();
179179
});
180180

181+
test('not throws if kafkaConsumerGroupId is token', () => {
182+
expect(() => new EventSourceMapping(stack, 'test', {
183+
eventSourceArn: 'arn:aws:kafka:us-east-1:123456789012:cluster/vpc-2priv-2pub/751d2973-a626-431c-9d4e-d7975eb44dd7-2',
184+
kafkaConsumerGroupId: cdk.Lazy.string({ produce: () => 'test' }),
185+
target: fn,
186+
})).not.toThrow();
187+
});
188+
181189
test('not throws if kafkaConsumerGroupId is valid for amazon managed kafka', () => {
182190
expect(() => new EventSourceMapping(stack, 'test', {
183191
eventSourceArn: 'arn:aws:kafka:us-east-1:123456789012:cluster/vpc-2priv-2pub/751d2973-a626-431c-9d4e-d7975eb44dd7-2',

0 commit comments

Comments
 (0)