AWS DynamoDB snippets

How scan an entire DynamoDB table with Python boto3 client

Please note that this snippet is part of the DynamoDB-Simpsons-episodes-full-example repository on GitHub.

Let's say you want to scan the data from a DynamoDB table using any cell of the table simpsonsEpisodes.

Please keep in mind that scan method is a very powerful, but very inefficient and very resource (and money) consuming way to find values in cells, because it scan every cell of every item of the table. For this reason it is better to avoid it if possible.

First of all, you have to create a Client (follow these steps) and then you can use the following code to assign a value to the variables used below.

table = dynamodbRes.Table(TABLENAME)

    response = table.scan(FilterExpression=Attr('Title').eq('The Princess Guide'))

The response code and the data of the item are stored in the response variable.

[{'Title': 'The Princess Guide', 'ProdCode': 'TABF08', 'OriginalAirDate': '2015-03-01', 'USViewers(millions)': Decimal('3.93'), 'No_Season': Decimal('26'), 'DirectedBy': {'Timothy Bailey'}, 'No_Overall': Decimal('567'), 'WrittenBy': {'Brian Kelley'}, 'No_Inseason': Decimal('15')}]

Back to AWS DynamoDB cookbook page