簡體   English   中英

如何使用 ResourceGroupsTaggingAPI boto3 列出 AWS 標記的托管區域

[英]How to list AWS tagged Hosted Zones using ResourceGroupsTaggingAPI boto3

我正在嘗試檢索所有使用 boto3 ResourceGroupsTaggingAPI 標記的 AWS 資源,但我似乎無法檢索已標記的托管區域。

tagFilters = [{'Key': 'tagA', 'Values': 'a'}, {'Key': 'tagB', 'Values': 'b'}]
client = boto3.client('resourcegroupstaggingapi', region_name = 'us-east-2')

paginator = self.client.get_paginator('get_resources')
page_list = paginator.paginate(TagFilters = tagFilters)

# filter and get iterable object arn
# Refer filtering with JMESPath => http://jmespath.org/
arns = page_list.search("ResourceTagMappingList[*].ResourceARN")

for arn in arns:
    print(arn)

我通過AWS 控制台中的標簽編輯器(我猜是使用 ResourceGroupsTaggingAPI)注意到當區域設置為所有標記的托管區域可以檢索(因為全局)而設置特定區域時標記的托管區域不是結果中顯示。 有沒有辦法將 boto3 客戶區域設置為全部?,還是有其他方法可以做到這一點?

我已經試過了

client = boto3.client('resourcegroupstaggingapi')

返回空結果( https://console.aws.amazon.com/resource-groups/tag-editor/find-resources?region=us-east-1

您需要遍歷所有區域,

ec2 = boto3.client('ec2')
region_response = ec2.describe_regions()
#print('Regions:', region_response['Regions'])
for this_region_info in region_response['Regions']:
  region = this_region_info["RegionName"]
  my_config = Config(
    region_name = region
  )
  client = boto3.client('resourcegroupstaggingapi', config=my_config)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM