1 回答

TA贡献1757条经验 获得超7个赞
应用过滤器时,describe_table_statistics 不遵守 MaxRecords 限制。
事实上,它似乎所做的是检索(2 x MaxRecords),应用过滤器,然后返回该集合。或者它可能检索 MaxRecords,应用过滤器,并继续直到结果集大于 MaxRecords。无论哪种方式,我的 while 条件都是问题所在。
我换了
while len(response['TableStatistics']) == max_records:
和
while 'Marker' in response:
现在该函数返回正确的记录数。
顺便说一句,我的第一次尝试是
while len(response['TableStatistics']) >= 1:
但在循环的最后一次迭代时,它抛出了这个错误:
KeyError: 'Marker'
完成的工作功能现在看起来是这样的:
def get_dms_task_tables(account, region, task_name, schema_name=None, table_state=None):
tables=[]
max_records=500
filters=[]
if schema_name:
filters.append({'Name':'schema-name', 'Values':[schema_name]})
if table_state:
filters.append({'Name':'table-state', 'Values':[table_state]})
task_arn = get_dms_task_arn(account, region, task_name)
session = boto3.Session(profile_name=account, region_name=region)
client = session.client('dms')
response = client.describe_table_statistics(
ReplicationTaskArn=task_arn
,Filters=filters
,MaxRecords=max_records)
tables += response['TableStatistics']
while 'Marker' in response:
response = client.describe_table_statistics(
ReplicationTaskArn=task_arn
,Filters=filters
,MaxRecords=max_records
,Marker=response['Marker'])
tables += response['TableStatistics']
return tables
添加回答
举报