aws glue crawler的web colsole中的Schema change policy部分包含3个点,而CloudFormation节模板只定义了2个点。是否有方法从cloudformation中设置"Inherit schema from table“参数?

发布于 2018-06-16 05:54:35
AWS控制台中的“使用表中的元数据更新所有新的和现有的分区”选项对应于在Crawler API Configuration字段中设置CrawlerOutput.Partitions.AddOrUpdateBehavior: InheritFromTable,如"Configuring a Crawler"文档中所述。
不幸的是,CloudFormation似乎还没有更新到支持在AWS::Glue::Crawler资源中设置Configuration属性。在CloudFormation的资源实现赶上更新的Glue API版本之前,通过CloudFormation更新的唯一方法是部署一个调用Lambda函数的Custom Resource,该函数使用Configuration JSON参数直接调用glue.updateCrawler API。您还需要一个IAM角色,该角色具有一个授予glue.updateCrawler操作权限的策略。
下面是一个完整的自定义资源实现,它将更新现有Crawler资源上的配置:
GlueConfigurationLambda:
Type: AWS::Lambda::Function
Properties:
Description: Adjusts Glue Configuration property.
FunctionName: GlueConfiguration
Handler: index.handler
Role: !GetAtt GlueConfigurationRole.Arn
Code:
ZipFile: |
const response = require("cfn-response");
const AWS = require("aws-sdk");
const glue = new AWS.Glue();
exports.handler = function (event, context) {
console.log("Request received:\n", JSON.stringify(event));
let physicalResourceId = event.ResourceProperties.CrawlerName;
const respond = (e) => response.send(event, context, e ? response.FAILED : response.SUCCESS, e ? e : {}, physicalResourceId);
process.on('uncaughtException', e=>respond(e));
try {
let configuration = (event.RequestType === 'Create' || event.RequestType === 'Update') ?
event.ResourceProperties.Configuration :
{};
if (configuration.Version) {
configuration.Version = parseFloat(configuration.Version);
}
glue.updateCrawler({
Name: physicalResourceId,
Configuration: JSON.stringify(configuration)
}).promise()
.then(data=>respond())
.catch(e=>respond(e));
} catch (e) { respond(e); }
};
Timeout: 30
Runtime: nodejs6.10
GlueConfigurationRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal: {Service: [lambda.amazonaws.com]}
Action: ['sts:AssumeRole']
Path: /
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
Policies:
- PolicyName: GluePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'glue:UpdateCrawler'
Resource: '*'
CrawlerConfiguration:
Type: Custom::CrawlerConfiguration
Properties:
ServiceToken: !GetAtt GlueConfigurationLambda.Arn
CrawlerName: !Ref Crawler
Configuration:
Version: '1.0'
CrawlerOutput:
Partitions:
AddOrUpdateBehavior: InheritFromTable发布于 2018-05-24 02:04:40
更新:从2018年8月23日起,您可以通过CloudFormation设置配置:
目前似乎没有任何方法来设置存储此设置的配置属性(请参阅API Documentation for Crawler)。
您可以使用boto3 (或其他SDK)更新配置属性。它接受如下的JSON字符串:
>>> import boto3
>>> client = boto3.client('glue')
>>> client.update_crawler(Name='CrawlerName',Configuration='{"Version": 1.0, "CrawlerOutput": { "Partitions": { "AddOrUpdateBehavior": "InheritFromTable" } } }')完成此操作后,我验证了在UI中选择了该选项,并在通过boto3或命令行界面检索爬行器信息时返回该选项。应该可以编写一个lambda函数,并将其作为自定义资源通过CloudFormation执行此更新(我目前正在评估Glue/雅典娜,并遇到了同样的问题)。
发布于 2018-04-25 13:57:18
您可以将crawler配置选项设置为InheritFromTable。此选项在AWS Glue控制台上命名为Update all new and existing partitions with metadata from the table。
设置此选项后,分区将从其父表中继承元数据属性,如分类、输入格式、输出格式、serde信息和架构。对父表的任何属性更改都会传播到它的分区。在现有crawler上设置此配置选项后,将在下次运行crawler时更新现有分区以匹配其父表的属性。
https://stackoverflow.com/questions/48344636
复制相似问题