我已经编写了一个python脚本,它根据传递的服务名称(如ec2、rds等(标记资源。我还标记了通过5个服务(ec2、rds、iam、cloudwatch、dynawdb(循环的"all"。大约有650个ARN需要标记。我知道每次调用.tag_resources((所花费的时间不超过20 arns。这个问题我已经通过使用大小为20的批次解决了。
然而,somewhen返回值包含"ErrorCode:Sthrottling",这意味着AWS端点拒绝调用。
你对解决这个问题有什么建议?我试着用time.sleep((,但还是有问题。
编辑:当排除"cloudwatch"时,它可以正常工作。
以下是执行get.resources((调用的helper函数的代码:
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资源组API绕过了这个问题。