Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要ECS帮助的Python Boto3_Python_Python 3.x_Amazon Web Services_Boto3_Amazon Ecs - Fatal编程技术网

需要ECS帮助的Python Boto3

需要ECS帮助的Python Boto3,python,python-3.x,amazon-web-services,boto3,amazon-ecs,Python,Python 3.x,Amazon Web Services,Boto3,Amazon Ecs,我对Python及其模块相当陌生。我正在尝试列出我的AWS ECS帐户中的所有群集。我有大约13个集群在运行 下面的代码只打印一个集群,而我想打印所有集群。它们是我可以使用的for循环吗 下面仅打印一个群集: import boto3 client = boto3.client('ecs') response = client.list_clusters( maxResults=50 ) print(response) 下面的for循环无效并抛出错误 import boto3 clie

我对Python及其模块相当陌生。我正在尝试列出我的AWS ECS帐户中的所有群集。我有大约13个集群在运行

下面的代码只打印一个集群,而我想打印所有集群。它们是我可以使用的for循环吗

下面仅打印一个群集:

import boto3
client = boto3.client('ecs')
response = client.list_clusters(
    maxResults=50
)
print(response)
下面的for循环无效并抛出错误

import boto3
client = boto3.client('ecs')
for response in client.list_cluster():
    print(response)
任何潜在客户都将不胜感激。

如果您查看api,响应语法为:

 Response Syntax

{
    'clusterArns': [
        'string',
    ],
    'nextToken': 'string'
}
这意味着您将返回一个列表(
[]
),其中有AWS中唯一的资源标识符

使用api获取描述,如@jordanm所说:

导入boto3
client=bot3.client('ecs',region_name='us-east-2')
clusters=client.list\u集群(
最大结果=50
)
clusters\u arns=簇['clusterArns']
clusters\u descriptions=client.description\u集群(
集群=集群
)
对于集群中的集群_描述['clusters']:
打印(群集['clusterName'])
结果是:

prod_nam
eu_nam
someothercluster

我的猜测是,您正在查询API以查找错误的AWS区域。您的ECS集群位于哪个区域?您在
~/.aws/credentials
~/.aws/config
中将哪个区域设置为默认区域?这两个区域都是us-east-2us-east-2?这是此帐户中唯一一个我与所有13个群集一起使用的区域如果您执行
client=boto3.client('ecs',region_name='us-east-2')