如何通过cloudformation为胶水爬虫设置“从表继承模式”?

时间:2018-01-19 15:41:36

标签: amazon-web-services amazon-cloudformation aws-glue

web colsole中用于aws glue crawler的

Schema change policy部分包含3个点,而cloudformation部分模板仅定义2.是否有办法从cloudformation模板设置“从表中继承模式”参数?

Cloudformation spec vs web console

4 个答案:

答案 0 :(得分:2)

AWS Console中的“使用表中的元数据更新所有新分区和现有分区”选项对应于在Crawler API CrawlerOutput.Partitions.AddOrUpdateBehavior: InheritFromTable字段中设置Configuration,如"Configuring a Crawler"中所述文档。

不幸的是,CloudFormation似乎尚未更新,无法支持在AWS::Glue::Crawler资源中设置Configuration属性。在CloudFormation的资源实现赶上更新的Glue API修订之前,通过CloudFormation更新此方法的唯一方法是部署Custom Resource调用Lambda函数,该函数使用{{1}调用glue.updateCrawler API直接JSON参数。您还需要具有授予Configuration操作权限的策略的IAM角色。

这是一个完整的自定义资源实现,它将更新现有glue.updateCrawler资源上的配置:

Crawler

答案 1 :(得分:1)

更新:自2018年8月23日起,您现在可以通过CloudFormation设置配置:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-glue-crawler.html#cfn-glue-crawler-configuration

目前似乎没有办法设置存储此设置的Configuration属性(请参阅API Documentation for Crawler)。

您可以使用boto3(或其他SDK)更新Configuration属性。它需要一个像这样的JSON字符串:

>>> import boto3
>>> client = boto3.client('glue')
>>> client.update_crawler(Name='CrawlerName',Configuration='{"Version": 1.0, "CrawlerOutput": { "Partitions": { "AddOrUpdateBehavior": "InheritFromTable" } } }')

我在执行此操作后验证了在UI中选择了该选项,并在通过boto3或CLI检索Crawler信息时返回。应该可以编写一个lambda函数并将其用作自定义资源,通过CloudFormation进行此更新(我目前正在评估Glue / Athena,并遇到同样的问题)。

答案 2 :(得分:0)

您可以将抓取工具配置选项设置为InheritFromTable。 此选项在AWS Glue控制台上命名为Update all new and existing partitions with metadata from the table

设置此选项后,分区会从其父表继承元数据属性,例如其分类,输入格式,输出格式,serde信息和架构。对父表的属性的任何更改都将传播到其分区。在现有爬网程序上设置此配置选项后,将在下次运行爬网程序时更新现有分区以匹配其父表的属性。

来源:Glue-CreateCrawler-request-Configuration

答案 3 :(得分:0)

使用Configuration属性通过CloudFormation设置“从表继承模式”。我已经尝试过了,并且对我有用。

"Type": "AWS::Glue::Crawler",
"Properties": {
   "Configuration": "{ \"Version\": 1.0, \"CrawlerOutput\": {\"Partitions\": { \"AddOrUpdateBehavior\": \"InheritFromTable\" }}}"
}

有关“配置”的详细信息-https://docs.aws.amazon.com/glue/latest/dg/crawler-configuration.html