Skip to content

Instantly share code, notes, and snippets.

@mulka
Created April 30, 2012 23:49
Show Gist options
  • Select an option

  • Save mulka/2563719 to your computer and use it in GitHub Desktop.

Select an option

Save mulka/2563719 to your computer and use it in GitHub Desktop.
boto batch write requests
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