@@ -308,6 +308,48 @@ describe('KafkaEventSource', () => {
308308 } ) ;
309309 } ) ;
310310
311+ test ( 'AT_TIMESTAMP starting position' , ( ) => {
312+ const stack = new cdk . Stack ( ) ;
313+ const fn = new TestFunction ( stack , 'Fn' ) ;
314+ const clusterArn = 'some-arn' ;
315+ const kafkaTopic = 'some-topic' ;
316+
317+ fn . addEventSource ( new sources . ManagedKafkaEventSource ( {
318+ clusterArn,
319+ topic : kafkaTopic ,
320+ startingPosition : lambda . StartingPosition . AT_TIMESTAMP ,
321+ startingPositionTimestamp : 1640995200 ,
322+ } ) ,
323+ ) ;
324+
325+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Lambda::EventSourceMapping' , {
326+ StartingPosition : 'AT_TIMESTAMP' ,
327+ StartingPositionTimestamp : 1640995200 ,
328+ } ) ;
329+ } ) ;
330+
331+ test ( 'startingPositionTimestamp missing throws error' , ( ) => {
332+ const clusterArn = 'some-arn' ;
333+ const kafkaTopic = 'some-topic' ;
334+
335+ expect ( ( ) => new sources . ManagedKafkaEventSource ( {
336+ clusterArn,
337+ topic : kafkaTopic ,
338+ startingPosition : lambda . StartingPosition . AT_TIMESTAMP ,
339+ } ) ) . toThrow ( / s t a r t i n g P o s i t i o n T i m e s t a m p m u s t b e p r o v i d e d w h e n s t a r t i n g P o s i t i o n i s A T _ T I M E S T A M P / ) ;
340+ } ) ;
341+
342+ test ( 'startingPositionTimestamp without AT_TIMESTAMP throws error' , ( ) => {
343+ const clusterArn = 'some-arn' ;
344+ const kafkaTopic = 'some-topic' ;
345+
346+ expect ( ( ) => new sources . ManagedKafkaEventSource ( {
347+ clusterArn,
348+ topic : kafkaTopic ,
349+ startingPosition : lambda . StartingPosition . LATEST ,
350+ startingPositionTimestamp : 1640995200 ,
351+ } ) ) . toThrow ( / s t a r t i n g P o s i t i o n T i m e s t a m p c a n o n l y b e u s e d w h e n s t a r t i n g P o s i t i o n i s A T _ T I M E S T A M P / ) ;
352+ } ) ;
311353 } ) ;
312354
313355 describe ( 'self-managed kafka' , ( ) => {
@@ -998,5 +1040,56 @@ describe('KafkaEventSource', () => {
9981040 expect ( mskEventMapping . eventSourceMappingId ) . toBeDefined ( ) ;
9991041 expect ( mskEventMapping . eventSourceMappingArn ) . toBeDefined ( ) ;
10001042 } ) ;
1043+
1044+ test ( 'AT_TIMESTAMP starting position' , ( ) => {
1045+ const stack = new cdk . Stack ( ) ;
1046+ const fn = new TestFunction ( stack , 'Fn' ) ;
1047+ const bootstrapServers = [ 'kafka-broker:9092' ] ;
1048+ const secret = new Secret ( stack , 'Secret' , { secretName : 'AmazonMSK_KafkaSecret' } ) ;
1049+ const kafkaTopic = 'some-topic' ;
1050+
1051+ fn . addEventSource ( new sources . SelfManagedKafkaEventSource ( {
1052+ bootstrapServers,
1053+ secret : secret ,
1054+ topic : kafkaTopic ,
1055+ startingPosition : lambda . StartingPosition . AT_TIMESTAMP ,
1056+ startingPositionTimestamp : 1640995200 ,
1057+ } ) ,
1058+ ) ;
1059+
1060+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Lambda::EventSourceMapping' , {
1061+ StartingPosition : 'AT_TIMESTAMP' ,
1062+ StartingPositionTimestamp : 1640995200 ,
1063+ } ) ;
1064+ } ) ;
1065+
1066+ test ( 'startingPositionTimestamp missing throws error' , ( ) => {
1067+ const stack = new cdk . Stack ( ) ;
1068+ const bootstrapServers = [ 'kafka-broker:9092' ] ;
1069+ const secret = new Secret ( stack , 'Secret' , { secretName : 'AmazonMSK_KafkaSecret' } ) ;
1070+ const kafkaTopic = 'some-topic' ;
1071+
1072+ expect ( ( ) => new sources . SelfManagedKafkaEventSource ( {
1073+ bootstrapServers,
1074+ secret : secret ,
1075+ topic : kafkaTopic ,
1076+ startingPosition : lambda . StartingPosition . AT_TIMESTAMP ,
1077+ } ) ) . toThrow ( / s t a r t i n g P o s i t i o n T i m e s t a m p m u s t b e p r o v i d e d w h e n s t a r t i n g P o s i t i o n i s A T _ T I M E S T A M P / ) ;
1078+ } ) ;
1079+
1080+ test ( 'startingPositionTimestamp without AT_TIMESTAMP throws error' , ( ) => {
1081+ const stack = new cdk . Stack ( ) ;
1082+ const bootstrapServers = [ 'kafka-broker:9092' ] ;
1083+ const secret = new Secret ( stack , 'Secret' , { secretName : 'AmazonMSK_KafkaSecret' } ) ;
1084+ const kafkaTopic = 'some-topic' ;
1085+
1086+ expect ( ( ) => new sources . SelfManagedKafkaEventSource ( {
1087+ bootstrapServers,
1088+ secret : secret ,
1089+ topic : kafkaTopic ,
1090+ startingPosition : lambda . StartingPosition . LATEST ,
1091+ startingPositionTimestamp : 1640995200 ,
1092+ } ) ) . toThrow ( / s t a r t i n g P o s i t i o n T i m e s t a m p c a n o n l y b e u s e d w h e n s t a r t i n g P o s i t i o n i s A T _ T I M E S T A M P / ) ;
1093+ } ) ;
10011094 } ) ;
10021095} ) ;
0 commit comments