首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过cloudformation为glue crawler设置“从表继承模式”?

问如何通过cloudformation为glue crawler设置“从表继承模式”?
EN

Stack Overflow用户
提问于 2018-01-19 23:41:36
回答 4查看 2.8K关注 0票数 4

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

​

​

EN

回答 4

Stack Overflow用户

发布于 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资源上的配置:

代码语言:javascript
复制
  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
票数 2
EN

Stack Overflow用户

发布于 2018-05-24 02:04:40

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

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

目前似乎没有任何方法来设置存储此设置的配置属性(请参阅API Documentation for Crawler)。

您可以使用boto3 (或其他SDK)更新配置属性。它接受如下的JSON字符串:

代码语言:javascript
复制
>>> import boto3
>>> client = boto3.client('glue')
>>> client.update_crawler(Name='CrawlerName',Configuration='{"Version": 1.0, "CrawlerOutput": { "Partitions": { "AddOrUpdateBehavior": "InheritFromTable" } } }')

完成此操作后,我验证了在UI中选择了该选项,并在通过boto3或命令行界面检索爬行器信息时返回该选项。应该可以编写一个lambda函数,并将其作为自定义资源通过CloudFormation执行此更新(我目前正在评估Glue/雅典娜,并遇到了同样的问题)。

票数 1
EN

Stack Overflow用户

发布于 2018-04-25 13:57:18

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

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

来源:Glue-CreateCrawler-request-Configuration

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48344636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档