@@ -93,11 +93,18 @@ type S3Event struct {
93
93
} `json:"detail"`
94
94
}
95
95
96
+ // For events that are published to SQS by SNS
97
+ // We only care about the message itself, the other SNS metadata are not needed
98
+ type SNSEvent struct {
99
+ Message string `json:"Message"`
100
+ }
101
+
96
102
const (
97
103
PollMethodList = "list"
98
104
PollMethodSQS = "sqs"
99
105
SQSFormatEventBridge = "eventbridge"
100
106
SQSFormatS3Notification = "s3notification"
107
+ SQSFormatSNS = "sns"
101
108
)
102
109
103
110
var linesRead = prometheus .NewCounterVec (
@@ -296,6 +303,16 @@ func extractBucketAndPrefixFromS3Notif(message *string) (string, string, error)
296
303
return s3notifBody .Records [0 ].S3 .Bucket .Name , s3notifBody .Records [0 ].S3 .Object .Key , nil
297
304
}
298
305
306
+ func extractBucketAndPrefixFromSNSNotif (message * string ) (string , string , error ) {
307
+ snsBody := SNSEvent {}
308
+ err := json .Unmarshal ([]byte (* message ), & snsBody )
309
+ if err != nil {
310
+ return "" , "" , err
311
+ }
312
+ //It's just a SQS message wrapped in SNS
313
+ return extractBucketAndPrefixFromS3Notif (& snsBody .Message )
314
+ }
315
+
299
316
func (s * S3Source ) extractBucketAndPrefix (message * string ) (string , string , error ) {
300
317
switch s .Config .SQSFormat {
301
318
case SQSFormatEventBridge :
@@ -310,6 +327,12 @@ func (s *S3Source) extractBucketAndPrefix(message *string) (string, string, erro
310
327
return "" , "" , err
311
328
}
312
329
return bucket , key , nil
330
+ case SQSFormatSNS :
331
+ bucket , key , err := extractBucketAndPrefixFromSNSNotif (message )
332
+ if err != nil {
333
+ return "" , "" , err
334
+ }
335
+ return bucket , key , nil
313
336
default :
314
337
bucket , key , err := extractBucketAndPrefixFromEventBridge (message )
315
338
if err == nil {
@@ -321,6 +344,11 @@ func (s *S3Source) extractBucketAndPrefix(message *string) (string, string, erro
321
344
s .Config .SQSFormat = SQSFormatS3Notification
322
345
return bucket , key , nil
323
346
}
347
+ bucket , key , err = extractBucketAndPrefixFromSNSNotif (message )
348
+ if err == nil {
349
+ s .Config .SQSFormat = SQSFormatSNS
350
+ return bucket , key , nil
351
+ }
324
352
return "" , "" , errors .New ("SQS message format not supported" )
325
353
}
326
354
}
@@ -506,8 +534,8 @@ func (s *S3Source) UnmarshalConfig(yamlConfig []byte) error {
506
534
return errors .New ("bucket_name is required" )
507
535
}
508
536
509
- if s .Config .SQSFormat != "" && s .Config .SQSFormat != SQSFormatEventBridge && s .Config .SQSFormat != SQSFormatS3Notification {
510
- return fmt .Errorf ("invalid sqs_format %s, must be empty, %s or %s" , s .Config .SQSFormat , SQSFormatEventBridge , SQSFormatS3Notification )
537
+ if s .Config .SQSFormat != "" && s .Config .SQSFormat != SQSFormatEventBridge && s .Config .SQSFormat != SQSFormatS3Notification && s . Config . SQSFormat != SQSFormatSNS {
538
+ return fmt .Errorf ("invalid sqs_format %s, must be empty, %s, %s or %s" , s .Config .SQSFormat , SQSFormatEventBridge , SQSFormatS3Notification , SQSFormatSNS )
511
539
}
512
540
513
541
return nil
0 commit comments