从AWS-ECS集群获取标签返回空列表

2024-10-02 12:32:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从我的ECS集群读取标签。我使用describeClusters()调用成功列出了我的所有集群。然后调用getTags(),它错误地返回一个空列表。你知道吗

    List<Cluster> clusters = clusterDescriptionResult.getClusters();
    for (Cluster cluster : clusters) {
        String clusterArn = cluster.getClusterArn();
        //System.out.println("Cluster: " + clusterArn);
        List<Tag> tagList = cluster.getTags();

我想我一定做了一些不对的事情,所以作为测试,我用Python重写了代码。你知道吗

    clusterList = ecsClient.list_clusters()
    for clusterArn in clusterList["clusterArns"]:
        tagListData = ecsClient.list_tags_for_resource(resourceArn=clusterArn)
        tagList = tagListData["tags"]

(编辑:这段Python代码工作得很好——请参阅注释了解它最初不工作的原因) 与其给我一个空列表,list\u tags\u for \u resource()更愿意抛出一个异常: AttributeError:'ECS'对象没有属性'list\u tags\u for \u resource'

在这一点上,我不得不怀疑。。。我有过期的包裹吗?根据我的说法pom.xml文件,我使用的是版本1.11.604(Java),或者boto3-1.9.202 botocore-1.12.202(Python),据我所知(2019年8月)。你知道吗

编辑:我现在已经从命令行尝试了,这确实有效:

    aws ecs list-tags-for-resource --resource-arn {cluster_arn}

Tags: 代码列表fortags集群resourcelistecs
1条回答
网友
1楼 · 发布于 2024-10-02 12:32:52

看起来这是API中的一个bug。解决方法是暂时使用ListTagsForResourceRequest()调用,它会正确返回集群的标记。你知道吗

    ListTagsForResourceRequest tagRequest = new ListTagsForResourceRequest().withResourceArn(clusterArn);
    ListTagsForResourceResult tagResult = amazonECS.listTagsForResource(tagRequest);
    List<Tag> tagList = tagResult.getTags();

相关问题 更多 >

    热门问题