JoakimMellonn
JoakimMellonn

Reputation: 160

Trigger Lambda function by S3 PUT in subfolder of undefined folder

I have an AWS Lambda function, that I want to trigger when a user uploads a file to a subfolder in their S3 directory.

Every user has its own folder inside the 'private/' prefix, but when the user is uploading a file, it's put in a subfolder. This means that the trigger prefix should be 'private/userID/subFolder/', but I can't find how to define that the userID could be anything.

I have tried making the prefix 'private/*/subFolder/', but that doesn't trigger anything. If I make the prefix 'private/', the function will be triggered unnecessarily.

What is the best way to do this?

Upvotes: 1

Views: 4149

Answers (2)

Hussain Mansoor
Hussain Mansoor

Reputation: 3134

You can't add a dynamic value for your trigger. So a solution is to get the event at a generic level like /prefix and then get the path of object. Extract the data you want and call your actual lambda. You can do this in 1 lambda as well and don't have to create 2.

S3 -> Lambda (extract path here) -> (actual) Lambda

Alternate solution is to add the message in SQS after parsing the path. And then call Any number of lambda's accordingly.

S3 -> Lambda (extract path here) -> Path1 -> SQS1 -> Lambda

OR

S3 -> Lambda (extract path here) -> SQS -> Lambda

Upvotes: 2

Marcin
Marcin

Reputation: 238827

You have to create a rule for each user:

private/userID1/subFolder
private/userID2/subFolder
private/userID3/subFolder

Upvotes: 0

Related Questions