Using wildcard in S3 event notification prefix

I have a Lambda function that creates a thumbnail for each image that loads in my bucket, then puts the Thumbnail in another bucket. When I upload a user image (pic profile), I use the user ID and name as part of the key:

System-images/users/250/john_doe.jpg

Is there a way to use a wildcard in a prefix path? This is what I have so far, but it does not work.

S3 basket properties

+5
source share
2 answers

No, you cannot - this is a literal prefix.

In your example, you can use any of these prefixes, depending on what else is in the bucket (if there is general information about a common prefix that you do not want to match):

 System-images/ System-images/users/ 
+6
source

Wildcards in Lambda prefix / suffix filters are still not supported, in the meantime you can partially filter them and then populate your filter by adding a regular expression inside your lambda function.

Get the source key:

 var srcKey = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " ")); 

Check if it is inside the user folder:

 if (srcKey.indexOf('/users/') === -1) { callback('Not inside users folder!'); return; } 
+1
source

Source: https://habr.com/ru/post/1233638/


All Articles