@@ -3,7 +3,7 @@ import { ISecurityGroup, IVpc, SubnetSelection } from '@aws-cdk/aws-ec2';
33import * as iam from '@aws-cdk/aws-iam' ;
44import * as lambda from '@aws-cdk/aws-lambda' ;
55import * as secretsmanager from '@aws-cdk/aws-secretsmanager' ;
6- import { Stack } from '@aws-cdk/core' ;
6+ import { Stack , Names } from '@aws-cdk/core' ;
77import { StreamEventSource , StreamEventSourceProps } from './stream' ;
88
99// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
@@ -101,15 +101,16 @@ export interface SelfManagedKafkaEventSourceProps extends KafkaEventSourceProps
101101export class ManagedKafkaEventSource extends StreamEventSource {
102102 // This is to work around JSII inheritance problems
103103 private innerProps : ManagedKafkaEventSourceProps ;
104+ private _eventSourceMappingId ?: string = undefined ;
104105
105106 constructor ( props : ManagedKafkaEventSourceProps ) {
106107 super ( props ) ;
107108 this . innerProps = props ;
108109 }
109110
110111 public bind ( target : lambda . IFunction ) {
111- target . addEventSourceMapping (
112- `KafkaEventSource:${ this . innerProps . clusterArn } ${ this . innerProps . topic } ` ,
112+ const eventSourceMapping = target . addEventSourceMapping (
113+ `KafkaEventSource:${ Names . nodeUniqueId ( target . node ) } ${ this . innerProps . topic } ` ,
113114 this . enrichMappingOptions ( {
114115 eventSourceArn : this . innerProps . clusterArn ,
115116 startingPosition : this . innerProps . startingPosition ,
@@ -118,6 +119,8 @@ export class ManagedKafkaEventSource extends StreamEventSource {
118119 } ) ,
119120 ) ;
120121
122+ this . _eventSourceMappingId = eventSourceMapping . eventSourceMappingId ;
123+
121124 if ( this . innerProps . secret !== undefined ) {
122125 this . innerProps . secret . grantRead ( target ) ;
123126 }
@@ -146,6 +149,16 @@ export class ManagedKafkaEventSource extends StreamEventSource {
146149 ? undefined
147150 : sourceAccessConfigurations ;
148151 }
152+
153+ /**
154+ * The identifier for this EventSourceMapping
155+ */
156+ public get eventSourceMappingId ( ) : string {
157+ if ( ! this . _eventSourceMappingId ) {
158+ throw new Error ( 'KafkaEventSource is not yet bound to an event source mapping' ) ;
159+ }
160+ return this . _eventSourceMappingId ;
161+ }
149162}
150163
151164/**
0 commit comments