Build an orchestrator using AWS Step Functions to automate the entire workflow. This state machine will execute the following sequence:
Unlike Glue Jobs, which support synchronous integration with .sync, the Glue Crawler API is asynchronous. That means when we click “Start”, it returns immediately even though the crawler is still running in the background. Because of that, our state machine needs a loop to check the crawler status:
RUNNING or STOPPING -> return to Wait.READY) -> move to the next step..sync suffix. At this point, Step Functions automatically waits until the job finishes. If the job fails, the entire state machine is marked FAILED (and it will trigger the EventBridge alert rule through SNS that we set up in the next section).Step 1: Open AWS Step Functions
In the AWS Console search bar, search for and select Step Functions.
Step 2: Create the State Machine
DataPipeline-Orchestrator.Step 3: Configure the Logic with ASL (Amazon States Language)
Instead of dragging and dropping each block manually in Workflow Studio, you can define the entire workflow in a few seconds by pasting the code.
{
"Comment": "Data Pipeline: Crawler -> Check Status -> ETL Job",
"StartAt": "Start Crawler",
"States": {
"Start Crawler": {
"Type": "Task",
"Parameters": {
"Name": "TEN_CRAWLER_CUA_BAN"
},
"Resource": "arn:aws:states:::aws-sdk:glue:startCrawler",
"Next": "Wait 30s"
},
"Wait 30s": {
"Type": "Wait",
"Seconds": 30,
"Next": "Get Crawler Status"
},
"Get Crawler Status": {
"Type": "Task",
"Parameters": {
"Name": "TEN_CRAWLER_CUA_BAN"
},
"Resource": "arn:aws:states:::aws-sdk:glue:getCrawler",
"Next": "Check Crawler State"
},
"Check Crawler State": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.Crawler.State",
"StringEquals": "RUNNING",
"Next": "Wait 30s"
},
{
"Variable": "$.Crawler.State",
"StringEquals": "STOPPING",
"Next": "Wait 30s"
}
],
"Default": "Run ETL Job"
},
"Run ETL Job": {
"Type": "Task",
"Resource": "arn:aws:states:::glue:startJobRun.sync",
"Parameters": {
"JobName": "TEN_GLUE_JOB_CUA_BAN"
},
"End": true
}
}
}
IMPORTANT UPDATE: You MUST find and replace the strings TEN_CRAWLER_CUA_BAN (in 2 places) and TEN_GLUE_JOB_CUA_BAN (in 1 place) in the code above with the exact crawler and ETL job names that you created in sections 4.1 and 4.3.
TEN_CRAWLER_CUA_BAN: glue_crawler_data
TEN_GLUE_JOB_CUA_BAN: glue_etl_job_taxi
Step 4: Verify the State Machine was successfully created
Great job! You now have a complete orchestrator (State Machine). It will start the crawler for you, wait patiently, and once the data is ready, it will trigger the Glue ETL Job.
Now that you have this Target (State Machine) in your account, go back to Step 4.4.2 to finish wiring up the EventBridge Rules automation from the previous section!