Skip to content

Instantly share code, notes, and snippets.

@dineshviswanath
Last active December 19, 2019 15:08
Show Gist options
  • Select an option

  • Save dineshviswanath/f578ccf0eaa3cc50511e5082a83f1eda to your computer and use it in GitHub Desktop.

Select an option

Save dineshviswanath/f578ccf0eaa3cc50511e5082a83f1eda to your computer and use it in GitHub Desktop.
batch insert DynamoDB
def dynamo_db_batch_write(items):
"""
Write in db by batch
"""
dynamo_db = boto3.resource(
'dynamodb',
endpoint_url=get_aws_endpoint_url('dynamodb'),
region_name=EOC_DYNAMO_DB_REGION,
)
table = dynamo_db.Table(EOC_DYNAMO_DB_NAME)
with table.batch_writer() as batch:
for item in items:
batch.put_item(Item=item)
logging.info('Batch insert done for {} records'.format(len(items)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment