Amazon DynamoDB
Query DynamoDB items by partition key
Use a key condition to read items for one partition key, with an optional sort-key condition. Run the query in the AWS CLI or page through the results in Go.
Documentation reviewed · 2 methods with sources
Ways to do it
CLI
aws dynamodb query
Use --table-name and --key-condition-expression with typed placeholder values. Add --index-name to query a secondary index.
Read source: AWS CLI DynamoDB query- Requirements
- AWS CLI with dynamodb:Query permission for the table or index, its name, and a partition key value.
- Limitations
- DynamoDB evaluates up to 1 MB in one request before applying a filter. Put key attributes in the key condition.
Example shell
aws dynamodb query --table-name ExampleTable --key-condition-expression 'pk = :key' --expression-attribute-values '{":key":{"S":"example"}}'SDK
dynamodb.NewQueryPaginator
Set TableName, KeyConditionExpression, and ExpressionAttributeValues on QueryInput. Use the paginator to follow each continuation key.
Read source: AWS SDK for Go v2 DynamoDB Query- Requirements
- An AWS SDK for Go v2 DynamoDB client with credentials, the table’s Region, and dynamodb:Query permission for the table or index.
- Limitations
- A filtered page can have no items and still have a LastEvaluatedKey. Continue until the paginator has no more pages.