Skip to content

Instantly share code, notes, and snippets.

@camin-mccluskey
Last active June 29, 2020 19:39
Show Gist options
  • Save camin-mccluskey/524aee15254fd94e963fd48534daa60d to your computer and use it in GitHub Desktop.
Save camin-mccluskey/524aee15254fd94e963fd48534daa60d to your computer and use it in GitHub Desktop.
Boto Example - Read from local dynamo
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