我已经编写了一个python脚本,该脚本基于传递的服务名(例如ec2,rds等)标记资源。我还标记了“ all”,它遍历5个服务(ec2,rds,iam,cloudwatch,dynamodb)。大约有650个ARN要标记。我知道eacht .tag_resources()调用最多需要20个arn。我已经通过使用大小为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
我通过使用AWS Resource Groups API绕过了问题。