Created
April 30, 2012 23:49
-
-
Save mulka/2563719 to your computer and use it in GitHub Desktop.
boto batch write requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import boto | |
| conn = boto.connect_dynamodb() | |
| def put_items(items_to_put): | |
| for table, puts in items_to_put.iteritems(): | |
| while(len(puts) > 0): | |
| unprocessed_items = [] | |
| for i in xrange(0, len(puts), 25): | |
| batch_list = conn.new_batch_write_list() | |
| batch_list.add_batch(table, puts=puts[i:i+25]) | |
| result = batch_list.submit() | |
| if table.name in result['UnprocessedItems']: | |
| unprocessed_items.extend(result['UnprocessedItems'][table.name]) | |
| puts = [] | |
| for unprocessed_item in unprocessed_items: | |
| attrs = unprocessed_item['PutRequest']['Item'] | |
| puts.append(table.new_item(attrs=attrs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment