【发布时间】:2020-04-03 11:48:10
【问题描述】:
我编写了一个 python 脚本,它根据传递的服务名称(如 ec2、rds 等)标记资源。 我还标记了循环通过 5 个服务(ec2、rds、iam、cloudwatch、dynamodb)的“所有”。大约有 650 个 ARN 需要标记。 我知道每个 .tag_resources() 调用不超过 20 个arns。这个问题我已经通过使用大小为 20 的批次解决了。
但是,当返回值包含“ErrorCode:Throttling”时,表示 AWS 端点拒绝调用。
您对解决此问题有何建议?我用 time.sleep() 试过了,但还是有问题。
编辑: 排除“cloudwatch”时,它工作得非常好。
这是执行 get.resource() 调用的辅助函数的代码:
def __tagHelper(self,arns,n,tags):
batches = chunks(arns,n) # arns is a list containing 650 object, n = 20
failedTagTrys=[]
for batch in batches: # batch is of size 20
response = self.client.tag_resources(
ResourceARNList=batch,
Tags=tags
)
failedTagTrys.append(response['FailedResourcesMap'])
# Clean up the list by removing empty dictionaries
cleaned_FailedTagTrys=list(filter(None, failedTagTrys))
return cleaned_FailedTagTrys
【问题讨论】:
标签: python amazon-web-services boto3 tagging