Boto3 ResourceGroupsTaggingAPI:如何处理错误代码 "Throttling"

Boto3 ResourceGroupsTaggingAPI: How to handle errorcode "Throttling"

我写了一个 python 脚本,它根据传递的服务名称(如 ec2、rds 等)标记资源。 我还标记了 'all' 循环通过 5 个服务(ec2、rds、iam、cloudwatch、dynamodb)。大约有 650 个 ARN 需要标记。 我知道每个 .tag_resources() 调用不超过 20 arns。这个问题我已经通过使用大小为 20 的批次解决了。

但是,当 return 值包含 '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 资源组API绕过了这个问题。