I want to activate a Step Function state machine when files are added to an Amazon Simple Storage Service (Amazon S3) bucket.
Short description
You can use an EventBridge rule to activate a Step Function state machine when an object is uploaded to an S3 bucket. You must have the following resources to get started:
- An S3 bucket where the object is uploaded
- A state machine that you want to run
- An EventBridge rule to invoke the state machine when the object is uploaded to the S3 bucket
Resolution
Prerequisite
Make sure that you have created a Step Function for your required task.
Complete these steps:
Create a bucket in Amazon S3
- Navigate to the Amazon S3 console.
- Choose Create bucket to create the bucket where you want to store your files.
- Enter a bucket name and other details.
- Create the bucket.
Activate Amazon S3 event notification with EventBridge
S3 bucket events aren't sent to the EventBridge bus, by default. You must activate it.
- Navigate to the Amazon S3 console.
- Choose the bucket that you want to activate events for.
- Choose Properties.
- Under the Event Notifications section, choose Edit in the Amazon EventBridge subsection.
- Under Send notifications to Amazon EventBridge for all events in this bucket, choose On.
- Choose Save changes.
Configure the state machine
Create a state machine.
Create an Amazon EventBridge rule
- Navigate to the Amazon EventBridge console, and then choose Create rule.
- Enter a Name for your rule.
- For Event bus and Rule type, keep the default selections.
- Choose Next. The Build event pattern page appears.
- Scroll down to the Event pattern section, and complete these steps:
- For Event source, keep the default selection of AWS Services.
- For AWS service, choose Simple Storage Service (S3).
- For Event type, choose Amazon S3 Event Notification.
- Choose Specific event(s), and then choose Object created.
- Choose Specific bucket(s) by name and enter the bucket name you created earlier.
- Choose Next to open the Select target(s) page.
- In Target 1, keep the default selection of AWS service.
- In the Select a target dropdown list, select Step Functions state machine.
- In the State machine dropdown list, select the state machine that you created earlier.
- Keep all the default selections on the page, and choose Next to open the Configure tags page.
- Choose Next again.
- Review the details of the rule, and then choose Create rule.
Use these troubleshooting tips
- The changes you make to activate S3 event notifications in EventBridge take about five minutes to complete. This means that the rule don't trigger immediately on S3 events after you activate it.
- If the rule doesn't trigger, make sure that the S3 bucket and the event rule are in same AWS Region.