如何使用 boto 列出我的 aws 账户中所有正在运行的集群?使用命令行我可以使用以下命令获取它们:
aws emr list-clusters --profile my-profile --region us-west-2 --active
不过我想使用 boto3 做同样的事情。但是以下代码不会返回任何簇:
import boto3
session = boto3.Session(profile_name='my-profile')
client = session.client('emr', region_name= 'us-west-2')
response = client.list_clusters(
ClusterStates=['RUNNING']
)
print response
Result:
{u'Clusters': [], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '577f3961-bdc80772f266', 'HTTPHeaders': {'x-amzn-requestid': '577f3961-34e5-11e7-a12a-bdc80772f266', 'date': 'Tue, 09 May 2017 18:28:47 GMT', 'content-length': '15', 'content-type': 'application/x-amz-json-1.1'}}}
这是分页器解决方案。
import boto3
boto3 = boto3.session.Session(region_name='ap-northeast-2')
emr = boto3.client('emr')
page_iterator = emr.get_paginator('list_clusters').paginate(
ClusterStates=['RUNNING','WAITING']
)
for page in page_iterator:
for item in page['Clusters']:
print(item['Id'])
结果是
j-21*****
j-3S*****
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)