我正在尝试检索使用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)
答案 0 :(得分:0)
你需要遍历所有区域,
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)