Skip to content

Commit 93cd776

Browse files
feat(lambda-event-sources): adds AuthenticationMethod.CLIENT_CERTIFICATE_TLS_AUTH to kafka (#17920)
This PR adds a new enum value, `CLIENT_CERTIFICATE_TLS_AUTH`, to `SelfManagedKafkaEventSource`. [Docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-sourceaccessconfiguration.html). ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3822c85 commit 93cd776

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export enum AuthenticationMethod {
5353
* BASIC_AUTH (SASL/PLAIN) authentication method for your Kafka cluster
5454
*/
5555
BASIC_AUTH = 'BASIC_AUTH',
56+
/**
57+
* CLIENT_CERTIFICATE_TLS_AUTH (mTLS) authentication method for your Kafka cluster
58+
*/
59+
CLIENT_CERTIFICATE_TLS_AUTH = 'CLIENT_CERTIFICATE_TLS_AUTH',
5660
}
5761

5862
/**
@@ -213,6 +217,9 @@ export class SelfManagedKafkaEventSource extends StreamEventSource {
213217
case AuthenticationMethod.BASIC_AUTH:
214218
authType = lambda.SourceAccessConfigurationType.BASIC_AUTH;
215219
break;
220+
case AuthenticationMethod.CLIENT_CERTIFICATE_TLS_AUTH:
221+
authType = lambda.SourceAccessConfigurationType.CLIENT_CERTIFICATE_TLS_AUTH;
222+
break;
216223
case AuthenticationMethod.SASL_SCRAM_256_AUTH:
217224
authType = lambda.SourceAccessConfigurationType.SASL_SCRAM_256_AUTH;
218225
break;

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

+35
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,41 @@ describe('KafkaEventSource', () => {
489489
});
490490
});
491491

492+
test('using CLIENT_CERTIFICATE_TLS_AUTH', () => {
493+
// GIVEN
494+
const stack = new cdk.Stack();
495+
const fn = new TestFunction(stack, 'Fn');
496+
const kafkaTopic = 'some-topic';
497+
const secret = new Secret(stack, 'Secret', { secretName: 'AmazonMSK_KafkaSecret' });
498+
const bootstrapServers = ['kafka-broker:9092'];
499+
const sg = SecurityGroup.fromSecurityGroupId(stack, 'SecurityGroup', 'sg-0123456789');
500+
const vpc = new Vpc(stack, 'Vpc');
501+
502+
// WHEN
503+
fn.addEventSource(new sources.SelfManagedKafkaEventSource(
504+
{
505+
bootstrapServers: bootstrapServers,
506+
topic: kafkaTopic,
507+
secret: secret,
508+
startingPosition: lambda.StartingPosition.TRIM_HORIZON,
509+
vpc: vpc,
510+
vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_NAT },
511+
securityGroup: sg,
512+
authenticationMethod: sources.AuthenticationMethod.CLIENT_CERTIFICATE_TLS_AUTH,
513+
}));
514+
515+
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::EventSourceMapping', {
516+
SourceAccessConfigurations: Match.arrayWith([
517+
{
518+
Type: 'CLIENT_CERTIFICATE_TLS_AUTH',
519+
URI: {
520+
Ref: 'SecretA720EF05',
521+
},
522+
},
523+
]),
524+
});
525+
});
526+
492527
test('ManagedKafkaEventSource name conforms to construct id rules', () => {
493528
// GIVEN
494529
const stack = new cdk.Stack();

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

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export class SourceAccessConfigurationType {
3535
*/
3636
public static readonly SASL_SCRAM_512_AUTH = new SourceAccessConfigurationType('SASL_SCRAM_512_AUTH');
3737

38+
/**
39+
* The Secrets Manager ARN of your secret key containing the certificate chain (X.509 PEM), private key (PKCS#8 PEM),
40+
* and private key password (optional) used for mutual TLS authentication of your MSK/Apache Kafka brokers.
41+
*/
42+
public static readonly CLIENT_CERTIFICATE_TLS_AUTH = new SourceAccessConfigurationType('CLIENT_CERTIFICATE_TLS_AUTH');
43+
3844
/** A custom source access configuration property */
3945
public static of(name: string): SourceAccessConfigurationType {
4046
return new SourceAccessConfigurationType(name);

0 commit comments

Comments
 (0)