Reputation: 1319
What's the best way to filter results with the begins_with method for boto3.dynamodb.condition.Key?
import boto3
from boto3.dynamodb.conditions import Key
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('MyTable')
response = table.query(KeyConditionExpression=Key('myPrimaryKey').begins_with('americas'))
The results, although conditions supports begins_with, is the query is not supported. Can you not use begins_with on primary or sort keys?
Upvotes: 1
Views: 11276
Reputation: 5747
Primary keys in DynamoDB can be either simple or composite.
Simple primary keys are consist of a partition key and no sort key.
Composite primary keys have both a partition key and a sort key.
You can only use begins_with
on the sort key, not the partition key.
Upvotes: 8