Reputation: 155
I need event notification when files with multiple extensions like .log, .txt, etc has been added to AWS s3 bucket. Can we add multiple suffix in s3 event notification from console ?
Upvotes: 15
Views: 19644
Reputation: 2428
You should use Lambda
with an S3
trigger to your bucket and edit the function code to check for the file type.
Eg. for Node JS
use something like this:
// Check that the file type is supported
const fileType = typeMatch[1].toLowerCase();
if (fileType != "txt" && fileType != "pdf") {
console.log(`Unsupported file type: ${fileType}`);
return;
}
Upvotes: 0
Reputation: 269550
You can create an Event in the Amazon S3 console, which can then trigger a Lambda function or send a message via SNS or SQS.
This configuration accepts a prefix
(effectively a directory) and a suffix
(eg .jpg
).
Simply open the bucket, go to the Properties tab and click Events (down the bottom).
See: Configuring Amazon S3 Event Notifications - Amazon Simple Storage Service
You can create multiple Events, each of which has a different suffix. But you can't create one Event with multiple suffixes. An alternative is to create an Event for any suffix (any file type), and have the Lambda function examine the filename and exit if it has an uninteresting suffix.
Upvotes: 17