@@ -10,7 +10,7 @@ const delay = timeout =>
10
10
} ) ;
11
11
12
12
class S3 {
13
- constructor ( lambda , resources , options , log ) {
13
+ constructor ( lambda , resources , options , { log} ) {
14
14
this . lambda = null ;
15
15
this . resources = null ;
16
16
this . options = null ;
@@ -48,30 +48,40 @@ class S3 {
48
48
return Promise . all (
49
49
this . events . map ( async ( { functionKey, s3} ) => {
50
50
const { event, bucket, rules} = s3 ;
51
- await this . _waitFor ( bucket ) ;
51
+ this . log . debug ( `Setting up listener for bucket: ${ bucket } , event: ${ event } ` ) ;
52
52
53
+ await this . _waitFor ( bucket ) ;
53
54
const eventRules = rules || [ ] ;
54
55
const prefix = ( eventRules . find ( rule => rule . prefix ) || { prefix : '*' } ) . prefix ;
55
56
const suffix = ( eventRules . find ( rule => rule . suffix ) || { suffix : '*' } ) . suffix ;
56
-
57
57
const listener = this . client . listenBucketNotification ( bucket , prefix , suffix , [ event ] ) ;
58
58
59
59
listener . on ( 'notification' , async record => {
60
60
if ( record ) {
61
61
try {
62
+ this . log . debug (
63
+ `Received S3 notification for bucket ${ bucket } : ${ JSON . stringify ( record ) } `
64
+ ) ;
62
65
const lambdaFunction = this . lambda . get ( functionKey ) ;
63
66
64
67
const s3Notification = new S3Event ( record ) ;
65
68
lambdaFunction . setEvent ( s3Notification ) ;
66
69
67
70
await lambdaFunction . runHandler ( ) ;
68
71
} catch ( err ) {
69
- this . log . warning ( err . stack ) ;
72
+ this . log . warning (
73
+ `Error processing S3 notification for bucket ${ bucket } : ${ err . stack } `
74
+ ) ;
70
75
}
71
76
}
72
77
} ) ;
73
78
79
+ listener . on ( 'error' , err => {
80
+ this . log . warning ( `Error in S3 listener for bucket ${ bucket } : ${ err . message } ` ) ;
81
+ } ) ;
82
+
74
83
this . listeners = [ ...this . listeners , listener ] ;
84
+ this . log . debug ( `Listener set up successfully for bucket: ${ bucket } ` ) ;
75
85
} )
76
86
) ;
77
87
}
0 commit comments