user3062260
user3062260

Reputation: 1644

Trigger an AWS state machine with an s3 put event via cloud trail

Has anyone been able to successfully trigger an aws state machine with an s3 put event? I have followed the instructions here but it seems very 'buggy', often there is a lengthy lag between a put event and when a cloudtrail log is written.

There also seems to be no instructions about how to configure an 'Event rule' so that it only triggers when files are placed in a specific sub-folder? Instead state machines seem to trigger in response to any file being added to the target bucket in any location, which makes it very risky to trigger the same state machine over in an infinite loop if output goes into the same bucket.

If anyone can add anything to the official docs for better clarity it would be a great help. Many thanks

Upvotes: 1

Views: 2716

Answers (1)

Deiv
Deiv

Reputation: 3097

CloudTrail logs can sometimes be slow, as mentioned in the CloudTrail FAQ under "How long does it take CloudTrail to deliver an event for an API call?":

Typically, CloudTrail delivers an event within 15 minutes of the API call.

Concerning the event rule for a specific sub-folder, it is currently (and someone update me if I'm wrong, might be outdated) possible only through an S3 Lambda trigger. The only thing you can do though through CloudWatch event rules is add a specific key to the event rule by following this guide, it just won't act as a prefix but would be a specific key that triggers the event, which might be helpful.

If a specific key doesn't suffice and you still need a prefix/suffix in your S3 trigger definition, then consider adding a Lambda that executes your step function, which is often used anyways because it allows you to customize the event sent to the step function. You can use the StartExecution API call from inside your Lambda, and setup an S3 Lambda trigger with a prefix, which you can find information on here.

Upvotes: 2

Related Questions