Last active
June 29, 2020 19:39
-
-
Save camin-mccluskey/524aee15254fd94e963fd48534daa60d to your computer and use it in GitHub Desktop.
Boto Example - Read from local dynamo
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 pprint import pprint | |
import boto3 | |
from botocore.exceptions import ClientError | |
def get_movie(title, year, dynamodb=None): | |
if not dynamodb: | |
dynamodb = boto3.resource('dynamodb', endpoint_url="http://localhost:8000") | |
table = dynamodb.Table('Movies') | |
try: | |
response = table.get_item(Key={'year': year, 'title': title}) | |
except ClientError as e: | |
print(e.response['Error']['Message']) | |
else: | |
return response['Item'] | |
if __name__ == '__main__': | |
movie = get_movie("The Big New Movie", 2015,) | |
if movie: | |
print("Get movie succeeded:") | |
pprint(movie, sort_dicts=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment