Home > Software engineering >  can object´s s3 bucket path decide upon lambda in step function?
can object´s s3 bucket path decide upon lambda in step function?

Time:09-18

i want to make the following process:

An object is placed in a folder of a s3 bucket. There is three folder available folder1, folder2 and folder3. From a event bridge notification a step function shall be invoked that offers three lambda functions that perfom an action. lambda1 shall be invoked for an object of folder1, lambda2 for objects in folder2 and lambda3 for objects in folder3. Does aws step functions offer this possibility? Can you give me an example how this looks in code?

CodePudding user response:

An Event Notification can be defined on an Amazon S3 bucket so that it triggers an AWS Lambda function when a new object is created. This Event can be defined at the top-level of the bucket, or on a specific prefix.

The easiest configuration for your situation would be to define three different events -- one for each Prefix, so that folder1 triggers lambda1, etc.

Alternatively, you could define one event that triggers the Step Function. The Step Function could then trigger an AWS Lambda function that extracts the Prefix (eg folder1) from the object Key that is supplied by S3. Then, the Lambda function can output the prefix. Step Functions can then apply Choice logic on that output to select which Lambda function to run.

See also: amazon s3 - Anyone has experience with triggering step function with S3 event? - Stack Overflow

Alternatively... I haven't tried this, but I notice that Choice - AWS Step Functions also allows wildcard matching. So, it might be possible that you can reference the Key supplied in the Event from S3 and try to match on the path (eg $.event.Key or something like that) and then test for folder1/*. Let us know if that works!

  • Related