次に記述してある制約条件を回避する方法です。
scan(**kwargs)
If the total number of scanned items exceeds
the maximum dataset size limit of 1 MB,
the scan stops
scan_id.py
#! /usr/bin/python
#
# scan_id.py
#
# Jul/22/2022
# --------------------------------------------------------------------
import sys
import json
import boto3
# --------------------------------------------------------------------
def scan_all(table, scan_kwargs):
items = []
done = False
start_key = None
while not done:
if start_key:
scan_kwargs['ExclusiveStartKey'] = start_key
response = table.scan(**scan_kwargs)
items.extend(response.get('Items', []))
start_key = response.get('LastEvaluatedKey', None)
done = start_key is None
return items
# --------------------------------------------------------------------
def list_id_proc(icount,unit):
str_out = str(icount) + '\t'
str_out += unit['id']
print(str_out)
# --------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
dynamodb = boto3.resource('dynamodb')
name_table = 'cities'
table = dynamodb.Table(name_table)
icount = 0
#
data = scan_all(table, {})
for unit in data:
list_id_proc(icount,unit)
icount += 1
#
sys.stderr.write("icount = %d\n" % icount)
sys.stderr.write("len(data) = %d\n" % len(data))
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------
レコード数のカウント
aws dynamodb scan --table-name cities --select "COUNT"