@@ -293,13 +293,62 @@ const DynamoDBv3EventCreator = {
293
293
} ,
294
294
} ;
295
295
296
+ const CloudWatchEventsv3EventCreator = {
297
+ /**
298
+ * Updates an event with the appropriate fields from an AWS CloudWatch Events command
299
+ * @param {string } operation the operation we wrapped.
300
+ * @param {Command } command the wrapped command
301
+ * @param {proto.event_pb.Event } event The event to update the data on
302
+ */
303
+ requestHandler ( operation , command , event ) {
304
+ const parameters = command . input || { } ;
305
+ const entry = parameters . Entries [ 0 ] || { } ;
306
+ const resource = event . getResource ( ) ;
307
+ resource . setType ( 'events' ) ;
308
+ switch ( operation ) {
309
+ case 'PutEventsCommand' :
310
+ resource . setName ( entry . EventBusName || 'CloudWatch Events' ) ;
311
+ eventInterface . addToMetadata ( event , {
312
+ 'aws.cloudwatch.detail_type' : entry . DetailType ,
313
+ 'aws.cloudwatch.resources' : entry . Resources ,
314
+ 'aws.cloudwatch.source' : entry . Source ,
315
+ } , {
316
+ 'aws.cloudwatch.detail' : entry . Detail ,
317
+ } ) ;
318
+ break ;
319
+ default :
320
+ break ;
321
+ }
322
+ } ,
323
+
324
+ /**
325
+ * Updates an event with the appropriate fields from an AWS CloudWatch Events response
326
+ * @param {string } operation the operation we wrapped.
327
+ * @param {object } response The AWS.Response object
328
+ * @param {proto.event_pb.Event } event The event to update the data on
329
+ */
330
+ responseHandler ( operation , response , event ) {
331
+ switch ( operation ) {
332
+ case 'PutEventsCommand' :
333
+ eventInterface . addToMetadata ( event , {
334
+ 'aws.cloudwatch.event_id' : `${ response . Entries [ 0 ] . EventId } ` ,
335
+ } ) ;
336
+ break ;
337
+
338
+ default :
339
+ break ;
340
+ }
341
+ } ,
342
+ } ;
343
+
296
344
/**
297
345
* a map between AWS resource names and their appropriate creator object.
298
346
*/
299
347
const specificEventCreators = {
300
348
sns : SNSv3EventCreator ,
301
349
dynamodb : DynamoDBv3EventCreator ,
302
350
sqs : SQSv3EventCreator ,
351
+ eventbridge : CloudWatchEventsv3EventCreator ,
303
352
} ;
304
353
305
354
/**
@@ -324,13 +373,14 @@ function getOperationByCommand(command) {
324
373
*/
325
374
function AWSSDKv3Wrapper ( wrappedFunction ) {
326
375
return function internalAWSSDKv3Wrapper ( command ) {
376
+ let responsePromise = wrappedFunction . apply ( this , [ command ] ) ;
327
377
try {
328
378
const serviceIdentifier = this . config . serviceId . toLowerCase ( ) ;
329
379
const resourceName = '' ;
330
380
331
381
if ( ! ( serviceIdentifier in specificEventCreators ) ) {
332
382
// resource is not supported yet
333
- return wrappedFunction . apply ( this , [ command ] ) ;
383
+ return responsePromise ;
334
384
}
335
385
336
386
const operation = getOperationByCommand ( command ) ;
@@ -351,7 +401,6 @@ function AWSSDKv3Wrapper(wrappedFunction) {
351
401
] ) ;
352
402
awsEvent . setResource ( resource ) ;
353
403
354
- let responsePromise = wrappedFunction . apply ( this , [ command ] ) ;
355
404
specificEventCreators [ serviceIdentifier ] . requestHandler (
356
405
operation ,
357
406
command ,
@@ -377,6 +426,7 @@ function AWSSDKv3Wrapper(wrappedFunction) {
377
426
} catch ( e ) {
378
427
tracer . addException ( e ) ;
379
428
}
429
+ return response ;
380
430
} ) . catch ( ( error ) => {
381
431
console . log ( error ) ;
382
432
try {
@@ -398,7 +448,7 @@ function AWSSDKv3Wrapper(wrappedFunction) {
398
448
} catch ( error ) {
399
449
tracer . addException ( error ) ;
400
450
}
401
- return wrappedFunction . apply ( this , [ command ] ) ;
451
+ return responsePromise ;
402
452
} ;
403
453
}
404
454
0 commit comments