- AWS Code Sample

# Copyright, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Shows how to get an item from an Amazon DynamoDB table that stores movies. The item is retrieved by using its primary and secondary keys. """ 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)