DynamoDB does not automatically index all fields of your object. By default, you can define a hash key ( subscription_id in your case) and, if necessary, a range key, and they will be indexed. So you can do this:
response = table.get_item(Key={'subscription_id': mysubid})
and it will work as expected. However, if you want to get an element based on order_number , you will need to use the scan operation, which scans all the elements in your table to find one with the correct value. This is a very expensive operation. Or you can create a global secondary index in your table that uses order_number as the primary key. If you did this and called the new order_number-index , you could query for objects matching a specific sequence number, as follows:
response = table.query( IndexName='order_number-index', KeyConditionExpression=Key('order_number').eq(myordernumber))
DynamoDB is a very fast, scalable and efficient database, but it takes a lot of thought about what fields you can look for and how to do it efficiently.
The good news is that now you can add GSI to your existing table. Previously, you had to delete the table and start all over again.
source share