0
votes

I want to fetch all items with query() from table not with scan as it is very expensive
Can I use .contains() without table.scan()

dynamodb = boto3.resource('dynamodb')
table= dynamodb.Table('investors')
data = table.scan(
        FilterExpression=Attr('groups_name').contains('person_name')
)

# Something like this
data = table.query(...
    ....    
    ('groups_name').contains('person_name')
)

In my DynamoDB -> investors (Table)(all have same partition key='fund')
-> sample item -> groups_name [list]: person_name (String)

1

1 Answers

2
votes

If you want to fetch all items from a table and have more than one partition key value, you will have to use Scan. The Query API operates on a single item collection (i.e. all items with the same partition key) and filtering using the FilterExpression can also be done there.

A contains filter isn't available for a KeyConditionExpression or the FilterExpression in the Query operation as well, the closest match would be starts_with, but that's different.

To handle this access pattern efficiently, you need to reconsider your data model.