Created
February 18, 2021 04:23
-
-
Save orcaman/b003c00adf2a76c255d41e5832630b77 to your computer and use it in GitHub Desktop.
DynamoDB Create From AWS Docs
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
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