Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created February 18, 2021 04:23
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 orcaman/b003c00adf2a76c255d41e5832630b77 to your computer and use it in GitHub Desktop.
Save orcaman/b003c00adf2a76c255d41e5832630b77 to your computer and use it in GitHub Desktop.
DynamoDB Create From AWS Docs
from decimal import Decimal
import json
import boto3
def load_movies(movies, dynamodb=None):
if not dynamodb:
dynamodb = boto3.resource('dynamodb', endpoint_url="http://localhost:8000")
table = dynamodb.Table('Movies')
for movie in movies:
year = int(movie['year'])
title = movie['title']
print("Adding movie:", year, title)
table.put_item(Item=movie)
if __name__ == '__main__':
with open("moviedata.json") as json_file:
movie_list = json.load(json_file, parse_float=Decimal)
load_movies(movie_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment