Skip to content
Latchkey

aws dynamodb query: Query a DynamoDB Table in CI

aws dynamodb query retrieves items sharing a partition key value via a key condition expression, optionally against a secondary index, the efficient read path versus a full scan.

Test assertions and deploy checks read DynamoDB with query (not scan). The expression-attribute mechanics and reserved-word escaping are where CI scripts stumble.

What it does

aws dynamodb query returns items matching --key-condition-expression (which must constrain the partition key, optionally the sort key) on --table-name or a --index-name. Placeholders :val bind via --expression-attribute-values and #name aliases via --expression-attribute-names to escape reserved words.

Common usage

Terminal
aws dynamodb query \
  --table-name deploys \
  --key-condition-expression 'pk = :p' \
  --expression-attribute-values '{":p":{"S":"my-service"}}' \
  --query 'Items[].sha.S' --output text

Options

FlagWhat it does
--table-name <name>Table to query (required)
--key-condition-expression <expr>Must constrain the partition key (required)
--expression-attribute-values {..}Bind :placeholders
--expression-attribute-names {..}Alias reserved words with #name
--index-name <name>Query a GSI/LSI instead of the base table
--filter-expression <expr>Post-filter after the key query

In CI

query needs an equality on the partition key; for arbitrary attribute filtering you need a scan or a suitable index. Escape reserved words (status, name, ttl) with --expression-attribute-names '{"#s":"status"}' and reference #s. Querying a GSI requires --index-name; results are eventually consistent on GSIs by default.

Common errors in CI

"An error occurred (ValidationException) when calling the Query operation: Query key condition not supported" means the key condition uses something other than the partition key equality (for example a non-key attribute). "ValidationException: Invalid ... reserved keyword" means an unescaped reserved word; use --expression-attribute-names. "ResourceNotFoundException" is a wrong table/index. "ProvisionedThroughputExceededException" means throttling; back off.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →