The following code writes items into Dynamodb in batch:
with table.batch_writer() as batch:
for item in chunk:
dynamodb_item = {
'itemId': item['key'],
'time': item['time'],
'value': item['value']
}
batch.put_item( Item = dynamodb_item )
As stated in the following docs, if the batch call fails it returns the unprocessed items: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Client.batch_write_item
In boto3, how can I get the unprocessed items in the response?
How can I figure out if it's all handled successfully or if the call response has unprocessed items?
Use batch_write_item
as you mentioned, instead of put_item
Check this example:
response = await client.batch_write_item(
RequestItems=request_items
)
if len(response['UnprocessedItems']) == 0:
print('Wrote 25 items to dynamo')
else:
await asyncio.sleep(5)
unprocessed_items = response['UnprocessedItems']
# proceed with unprocessed_items