1 回答

TA貢獻1757條經驗 獲得超7個贊
應用過濾器時,describe_table_statistics 不遵守 MaxRecords 限制。
事實上,它似乎所做的是檢索(2 x MaxRecords),應用過濾器,然后返回該集合?;蛘咚赡軝z索 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
添加回答
舉報