[英]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.