Skip to content

Instantly share code, notes, and snippets.

@em-shea
Last active July 3, 2022 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save em-shea/8fd7b4d96852329237790285a6715bae to your computer and use it in GitHub Desktop.
Save em-shea/8fd7b4d96852329237790285a6715bae to your computer and use it in GitHub Desktop.
Example script to export DynamoDB table data
import json
import boto3
# Specify your table name and the region your table is in
export_table_name = "ExportDataTable"
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table(export_table_name)
def export_table_data():
print(f"Exporting data from {export_table_name}")
response = table.scan()
data = response['Items']
# Paginate through DynamoDB table response
while 'LastEvaluatedKey' in response:
response = table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
data.extend(response['Items'])
# Create or open a text file to save exported data
with open(f"data_export_{export_table_name}.json","w+") as f:
json_data = json.dumps(data)
f.write(json_data)
print("Export complete!")
export_table_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment