【问题标题】:AWS Boto3 EMR Software Settings Configuration From S3来自 S3 的 AWS Boto3 EMR 软件设置配置
【发布时间】:2018-06-22 08:22:27
【问题描述】:

当您通过 AWS 管理控制台创建新的 AWS EMR 集群时,您可以提供 JSON 软件配置。您可以将 JSON 文件放在 S3 存储桶中,并通过以下字段将软件配置指向 S3 存储桶,

我需要通过 AWS Python SDK Boto3 库执行此操作,但在他们的示例中的可用字段中我看不到在哪里执行此操作,

response = client.run_job_flow(
    Name='string',
    LogUri='string',
    AdditionalInfo='string',
    AmiVersion='string',
    ReleaseLabel='string',
    Instances={
        'MasterInstanceType': 'string',
        'SlaveInstanceType': 'string',
        'InstanceCount': 123,
        'InstanceGroups': [
            {
                'Name': 'string',
                'Market': 'ON_DEMAND'|'SPOT',
                'InstanceRole': 'MASTER'|'CORE'|'TASK',
                'BidPrice': 'string',
                'InstanceType': 'string',
                'InstanceCount': 123,
                'Configurations': [
                    {
                        'Classification': 'string',
                        'Configurations': {'... recursive ...'},
                        'Properties': {
                            'string': 'string'
                        }
                    },
                ],
                'EbsConfiguration': {
                    'EbsBlockDeviceConfigs': [
                        {
                            'VolumeSpecification': {
                                'VolumeType': 'string',
                                'Iops': 123,
                                'SizeInGB': 123
                            },
                            'VolumesPerInstance': 123
                        },
                    ],
                    'EbsOptimized': True|False
                },
                'AutoScalingPolicy': {
                    'Constraints': {
                        'MinCapacity': 123,
                        'MaxCapacity': 123
                    },
                    'Rules': [
                        {
                            'Name': 'string',
                            'Description': 'string',
                            'Action': {
                                'Market': 'ON_DEMAND'|'SPOT',
                                'SimpleScalingPolicyConfiguration': {
                                    'AdjustmentType': 'CHANGE_IN_CAPACITY'|'PERCENT_CHANGE_IN_CAPACITY'|'EXACT_CAPACITY',
                                    'ScalingAdjustment': 123,
                                    'CoolDown': 123
                                }
                            },
                            'Trigger': {
                                'CloudWatchAlarmDefinition': {
                                    'ComparisonOperator': 'GREATER_THAN_OR_EQUAL'|'GREATER_THAN'|'LESS_THAN'|'LESS_THAN_OR_EQUAL',
                                    'EvaluationPeriods': 123,
                                    'MetricName': 'string',
                                    'Namespace': 'string',
                                    'Period': 123,
                                    'Statistic': 'SAMPLE_COUNT'|'AVERAGE'|'SUM'|'MINIMUM'|'MAXIMUM',
                                    'Threshold': 123.0,
                                    'Unit': 'NONE'|'SECONDS'|'MICRO_SECONDS'|'MILLI_SECONDS'|'BYTES'|'KILO_BYTES'|'MEGA_BYTES'|'GIGA_BYTES'|'TERA_BYTES'|'BITS'|'KILO_BITS'|'MEGA_BITS'|'GIGA_BITS'|'TERA_BITS'|'PERCENT'|'COUNT'|'BYTES_PER_SECOND'|'KILO_BYTES_PER_SECOND'|'MEGA_BYTES_PER_SECOND'|'GIGA_BYTES_PER_SECOND'|'TERA_BYTES_PER_SECOND'|'BITS_PER_SECOND'|'KILO_BITS_PER_SECOND'|'MEGA_BITS_PER_SECOND'|'GIGA_BITS_PER_SECOND'|'TERA_BITS_PER_SECOND'|'COUNT_PER_SECOND',
                                    'Dimensions': [
                                        {
                                            'Key': 'string',
                                            'Value': 'string'
                                        },
                                    ]
                                }
                            }
                        },
                    ]
                }
            },
        ],
        'InstanceFleets': [
            {
                'Name': 'string',
                'InstanceFleetType': 'MASTER'|'CORE'|'TASK',
                'TargetOnDemandCapacity': 123,
                'TargetSpotCapacity': 123,
                'InstanceTypeConfigs': [
                    {
                        'InstanceType': 'string',
                        'WeightedCapacity': 123,
                        'BidPrice': 'string',
                        'BidPriceAsPercentageOfOnDemandPrice': 123.0,
                        'EbsConfiguration': {
                            'EbsBlockDeviceConfigs': [
                                {
                                    'VolumeSpecification': {
                                        'VolumeType': 'string',
                                        'Iops': 123,
                                        'SizeInGB': 123
                                    },
                                    'VolumesPerInstance': 123
                                },
                            ],
                            'EbsOptimized': True|False
                        },
                        'Configurations': [
                            {
                                'Classification': 'string',
                                'Configurations': {'... recursive ...'},
                                'Properties': {
                                    'string': 'string'
                                }
                            },
                        ]
                    },
                ],
                'LaunchSpecifications': {
                    'SpotSpecification': {
                        'TimeoutDurationMinutes': 123,
                        'TimeoutAction': 'SWITCH_TO_ON_DEMAND'|'TERMINATE_CLUSTER',
                        'BlockDurationMinutes': 123
                    }
                }
            },
        ],
        'Ec2KeyName': 'string',
        'Placement': {
            'AvailabilityZone': 'string',
            'AvailabilityZones': [
                'string',
            ]
        },
        'KeepJobFlowAliveWhenNoSteps': True|False,
        'TerminationProtected': True|False,
        'HadoopVersion': 'string',
        'Ec2SubnetId': 'string',
        'Ec2SubnetIds': [
            'string',
        ],
        'EmrManagedMasterSecurityGroup': 'string',
        'EmrManagedSlaveSecurityGroup': 'string',
        'ServiceAccessSecurityGroup': 'string',
        'AdditionalMasterSecurityGroups': [
            'string',
        ],
        'AdditionalSlaveSecurityGroups': [
            'string',
        ]
    },
    Steps=[
        {
            'Name': 'string',
            'ActionOnFailure': 'TERMINATE_JOB_FLOW'|'TERMINATE_CLUSTER'|'CANCEL_AND_WAIT'|'CONTINUE',
            'HadoopJarStep': {
                'Properties': [
                    {
                        'Key': 'string',
                        'Value': 'string'
                    },
                ],
                'Jar': 'string',
                'MainClass': 'string',
                'Args': [
                    'string',
                ]
            }
        },
    ],
    BootstrapActions=[
        {
            'Name': 'string',
            'ScriptBootstrapAction': {
                'Path': 'string',
                'Args': [
                    'string',
                ]
            }
        },
    ],
    SupportedProducts=[
        'string',
    ],
    NewSupportedProducts=[
        {
            'Name': 'string',
            'Args': [
                'string',
            ]
        },
    ],
    Applications=[
        {
            'Name': 'string',
            'Version': 'string',
            'Args': [
                'string',
            ],
            'AdditionalInfo': {
                'string': 'string'
            }
        },
    ],
    Configurations=[
        {
            'Classification': 'string',
            'Configurations': {'... recursive ...'},
            'Properties': {
                'string': 'string'
            }
        },
    ],
    VisibleToAllUsers=True|False,
    JobFlowRole='string',
    ServiceRole='string',
    Tags=[
        {
            'Key': 'string',
            'Value': 'string'
        },
    ],
    SecurityConfiguration='string',
    AutoScalingRole='string',
    ScaleDownBehavior='TERMINATE_AT_INSTANCE_HOUR'|'TERMINATE_AT_TASK_COMPLETION',
    CustomAmiId='string',
    EbsRootVolumeSize=123,
    RepoUpgradeOnBoot='SECURITY'|'NONE',
    KerberosAttributes={
        'Realm': 'string',
        'KdcAdminPassword': 'string',
        'CrossRealmTrustPrincipalPassword': 'string',
        'ADDomainJoinUser': 'string',
        'ADDomainJoinPassword': 'string'
    }
)

如何提供一个 S3 存储桶位置,其中包含用于通过 Boto3 库创建 EMR 集群的软件配置 JSON 文件?

【问题讨论】:

    标签: amazon-web-services boto3 amazon-emr


    【解决方案1】:

    目前 boto3 SDK 无法直接从 s3 导入配置设置作为 run_job_flow() 函数的一部分。您需要在 boto3 中设置 S3 客户端,将数据下载为 S3 对象,然后使用 S3 文件中的 JSON 数据更新 EMR 字典的配置列表部分。

    可以在此处找到如何从 S3 下载 json 文件然后将其作为 Python Dict 加载到内存中的示例 - Reading an JSON file from S3 using Python boto3

    【讨论】:

    • 我喜欢这个答案。只是为了澄清一下,我把这个 JSON 放在response = client.run_job_flow(...,Configurations=theS3JsonThatWeRetrieved,...) 下,对吗?
    • 根据 run_job_flow 字典的构建方式,您需要将这些配置添加到您定义的每个 InstanceGroups 元素和 InstanceFleets 元素中,因此类似于 run_job_flow(...,Instances={ 'InstanceGroups':[ { ..., 'Configurations' : theS3JsonThatWeRetrieved,... }],...'InstanceFleets':[{..., 'Configurations' : theS3JsonThatWeRetrieved,...} ]})。 InstanceGroups 和 InstanceFleets 都是 run_job_flow 函数的可选值,因此您只需要定义所需的特定值
    • huma474 我有点困惑我必须在 InstanceGroups 和 InstanceFleets 中填写什么,因为我目前没有设置这些字段。我的目前看起来像这样Instances={'MasterInstanceType': 'r4.xlarge','SlaveInstanceType': 'r4.xlarge','InstanceCount': 4,'KeepJobFlowAliveWhenNoSteps': False,'TerminationProtected': False}。我有 JSON 配置文件,但我不确定是否只需要在 Groups/Fleets 中设置配置字段,还是必须填写其他字段?介意举个例子吗?
    • 请注意。事实证明,您不必填写 InstanceGroups 或 InstanceFleets 中的配置,您只需在配置字段中填写即可,请参阅此处以获取参考 boto3.readthedocs.io/en/latest/reference/services/…
    【解决方案2】:

    Configuring Applications - Amazon EMR 文档说:

    在控制台中提供配置

    要提供配置,请导航到创建集群页面并选择编辑软件设置。然后,您可以在控制台中直接输入配置(以 JSON 格式或使用阴影文本中演示的速记语法),或为带有 JSON Configurations 对象的文件提供 Amazon S3 URI。

    这似乎是您在问题中展示的能力。

    文档随后显示了如何通过 CLI 进行操作:

    aws emr create-cluster --use-default-roles --release-label emr-5.14.0 --instance-type m4.large --instance-count 2 --applications Name=Hive --configurations https://s3.amazonaws.com/mybucket/myfolder/myConfig.json
    

    这映射到您在上面显示的 JSON 中的 配置 选项:

                        'Configurations': [
                            {
                                'Classification': 'string',
                                'Configurations': {'... recursive ...'},
                                'Properties': {
                                    'string': 'string'
                                }
                            },
                        ]
    

    配置:配置集群实例时应用的配置分类,其中可以包括在集群上运行的应用程序和软件的配置。

    它将包含如下设置:

    [
      {
        "Classification": "core-site",
        "Properties": {
          "hadoop.security.groups.cache.secs": "250"
        }
      },
      {
        "Classification": "mapred-site",
        "Properties": {
          "mapred.tasktracker.map.tasks.maximum": "2",
          "mapreduce.map.sort.spill.percent": "0.90",
          "mapreduce.tasktracker.reduce.tasks.maximum": "5"
        }
      }
    ]
    

    简答: Configurations

    【讨论】:

      猜你喜欢
      • 2019-05-26
      • 2017-12-16
      • 2016-04-05
      • 2017-08-09
      • 2018-07-11
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 1970-01-01
      相关资源
      最近更新 更多