Reputation: 1529
I'm writing an automated image resizing tool for S3 using Lambda. I'd like to create thumbnails in a subfolder of the bucket upon a PUT operation but if I put a file anywhere in the bucket the event is fired.
Can some tell me how to make the event on fire on just actions in the root of the specified bucket but no in its subfolders?
Upvotes: 3
Views: 4541
Reputation: 3306
Use a prefix filter. For example, configure your trigger with a prefix filter of uploads/
. It will fire when uploads/thumb1.jpg
is created but not when any_other_prefix/thumb1.jpg
is created. Then, just make sure when you PUT your thumbnails you use prefix in the key.
Upvotes: 7
Reputation: 3181
It doesn't look like you can configure the S3 notification to fire only on certain paths, so the best option is to implement this logic in your Lambda function:
var key = event.Records[0].s3.object.key;
if (key.indexOf('/') === -1) {
// No slash in key name, must be in root of bucket, do stuff here
}
This will work because if the object is in a subfolder and not the root, the key will have a slash in the name.
Upvotes: 3