简体   繁体   English

尝试使用 boto3 为 EMR 获取实例类型和计数时出错

[英]Error while trying to get INSTANCETYPE AND COUNT using boto3 for EMR

Am trying to fetch EMR Core instance type, and Running instance counts.我正在尝试获取 EMR Core 实例类型和正在运行的实例计数。 The following aws cli command works fine, and am trying to fetch it using boto3, using custom filter, but getting issue.以下 aws cli 命令工作正常,我正在尝试使用 boto3、使用自定义过滤器获取它,但遇到了问题。

AWS CLI command: AWS CLI 命令:

aws emr describe-cluster --cluster-id 'j-xxxxxx' --profile=dev --query 'Cluster.InstanceGroups[?InstanceGroupType==`CORE`].[InstanceType, RunningInstanceCount]'

The response for above command:上述命令的响应:

[
    [
        "CORE", 
        "c4.8xlarge", 
        10
    ]
]

Am trying to use boto3 using a custom_filter, but getting errors with custom_filter.我正在尝试通过 custom_filter 使用 boto3,但在使用 custom_filter 时出现错误。

cluster_id = 'j-xxxxx'
custom_filter = [{'Name':"ClusterId", 'Values': [cluster_id]},
                     {'Name': "InstanceGroupType", 'Values': 'CORE'}]
print(custom_filter)
response = emr_client.list_instance_groups(Filters = custom_filter)

The error message in EMR logs:
Traceback (most recent call last):
  File "/mnt/tmp/spark-ea1adb4d-ff6f-4bbd-8eae-39e89cf5ba47/boto3_emrec2_test.py", line 108, in <module>
    boto3_test()
  File "/mnt/tmp/spark-ea1adb4d-ff6f-4bbd-8eae-39e89cf5ba47/boto3_emrec2_test.py", line 66, in boto3_test
    response = emr_client.list_instance_groups(Filters = custom_filter)
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 391, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 692, in _make_api_call
    api_params, operation_model, context=request_context)
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 740, in _convert_to_request_dict
    api_params, operation_model)
  File "/usr/local/lib/python3.7/site-packages/botocore/validate.py", line 360, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Missing required parameter in input: "ClusterId"
Unknown parameter in input: "Filters", must be one of: ClusterId, Marker

Have also tried with tag:ClusterID, tag:Id, etc. but getting the same error.还尝试使用 tag:ClusterID、tag:Id 等,但出现相同的错误。 Appreciate any pointers.感谢任何指针。

I am able to get the instance_type and running instance count using the following code snippet in boto3:我可以在 boto3 中使用以下代码片段获取 instance_type 和运行实例计数:

emr_client = boto3.client("emr")
cluster_id = 'j-xxxxxx'
response = emr_client.list_instance_groups(ClusterId = cluster_id)
    core_info = list(filter(lambda m: 'CORE' in m["InstanceGroupType"], response["InstanceGroups"]))
    instance_type = core_info[0]['InstanceType']
    core_instance_count = core_info[0]['RunningInstanceCount']

And if you would need vCPUs for a given instance, the following will return the vCPUs:如果您需要给定实例的 vCPU,以下将返回 vCPU:

instance_dtl = ec2_client.describe_instance_types(InstanceTypes=[instance_type])
current_vcpu_count = instance_dtl['InstanceTypes'][0]['VCpuInfo']['DefaultVCpus']

Hope it will be useful for someone.希望它对某人有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Boto3 获取特定 S3 文件夹中的对象数 - Get count of objects in a specific S3 folder using Boto3 使用 Boto3 描述侦听器规则计数 - Describe listener rule count using Boto3 使用 boto3 更新 ecs 的最小计数 - Updating the minimum count for ecs using boto3 使用 boto3 创建 S3 生命周期策略时出现格式错误的 XML 错误 - Malformed XML error while creating the S3 life cycle policy using boto3 AWS CLI 或 boto3:尝试获取可用性区域 ID? - AWS CLI or boto3: Trying to get the availability-zone id? Arguments 对于 jar 文件不正确 - 使用 Boto3 启动 EMR 集群 - Arguments for jar file incorrect - spinning up EMR cluster using Boto3 在使用客户端 Boto3 时获取没有父文件夹前缀的确切文件名 SDK - To get the exact filename without the prefix of parent folders while using client Boto3 SDK 使用 lambda boto3 描述侦听器规则计数 - Describe listener rule count using lambda boto3 使用 boto3 的 StreamingBody.iter_lines() 遍历 S3 中的文件是否算作每一行的 GET 请求? - Does iterating through a file in S3 using boto3's StreamingBody.iter_lines() count as a GET request for each line? 使用 boto3 获取多个 aws 帐户 ec2 库存 - Get multiple aws account ec2 inventory using boto3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM