BoI*_*Ide 5 amazon-s3 amazon-web-services aws-glue
是否可以在新文件上触发AWS Glue爬虫,并将其上传到S3存储桶,因为爬虫是"指向"该存储桶的?换句话说:文件上传会生成一个事件,导致AWS Glue抓取工具对其进行分析.我知道有基于计划的爬行,但从未找到基于事件的爬行.
Pat*_*era 15
作为快速入门,这里详细介绍了如何在 Python 中创建 Lambda 来执行此操作。这是我第一次创建一个 Lambda,所以 YMMV。
"Action": "glue:StartCrawler", "Resource": "*"
from __future__ import print_function
import json
import boto3
print('Loading function')
glue = boto3.client(service_name='glue', region_name='ap-southeast-2',
endpoint_url='https://glue.ap-southeast-2.amazonaws.com')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
try:
glue.start_crawler(Name='my-glue-crawler')
except Exception as e:
print(e)
print('Error starting crawler')
raise e
Run Code Online (Sandbox Code Playgroud)
最后,假设您选择在开发时禁用触发器,从设计器面板单击 S3 触发器并确保它已启用(您可能需要在进行此更改后保存 lambda)
就是这样,但请注意,如果爬虫已经在运行,则会引发异常,因此如果您经常上传或爬行时间过长,您将需要处理该异常。请参阅:https : //docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-crawling.html#aws-glue-api-crawler-crawling-StartCrawler
编辑:
这帮助我处理异常(来自 AWS Glue):https : //github.com/boto/boto3/issues/1606#issuecomment-401423567
不,目前没有直接的方法来调用AWS Glue爬虫来响应上传到S3存储桶.S3事件通知只能发送到:
但是,编写一小段Lambda代码以使用相关语言SDK以编程方式调用Glue爬虫是很简单的.
| 归档时间: |
|
| 查看次数: |
4037 次 |
| 最近记录: |