例如,我运行 ETL,可能会为目标表添加新字段或列。要检测表更改,应运行爬虫,但它只能手动或计划运行。
作业完成后可以触发爬虫吗?
import boto3
glue_client = boto3.client('glue', region_name='us-east-1')
glue_client.start_crawler(Name='name_of_crawler')
在代码末尾复制此代码段。
您可以使用触发器,但不能在触发器 UI 中使用:S
使用 Glue 工作流程:添加触发器以启动作业、添加作业、添加触发器以获取作业成功、为触发的内容添加爬虫
或者,使用 CLI:
aws glue create-trigger --name myJob-success \
--type CONDITIONAL \
--predicate '{"Logical":"ANY","Conditions":[{"JobName":"myJob","LogicalOperator":"EQUALS","State":"SUCCEEDED"}]}' \
--actions CrawlerName=myCrawler \
--start-on-creation
或在 CloudFormation 中:
Type: AWS::Glue::Trigger
Properties:
Name: job_success
Type: CONDITIONAL
Predicate:
Logical: ANY
Conditions:
- JobName: myJob
LogicalOperator: EQUALS
State: SUCCEEDED
Actions:
- CrawlerName:myCrawler