[AWS CLI] Query a DynamoDB global secondary index

Created on November 30, 2026

You can use aws dynamodb query to retrieve items from a global secondary index by its partition key. This example looks for category = user in the category-index index on DummyTable.

aws dynamodb query \
  --table-name DummyTable \
  --index-name category-index \
  --key-condition-expression "category = :category" \
  --expression-attribute-values '{":category": {"S": "user"}}'

S marks the value as a DynamoDB string. Here is an example response.

{
    "Items": [
        {
            "category": {
                "S": "user"
            },
            "id": {
                "S": "2"
            },
            "name": {
                "S": "tanaka"
            },
            "age": {
                "N": "20"
            }
        },
        {
            "category": {
                "S": "user"
            },
            "id": {
                "S": "1"
            },
            "name": {
                "S": "suzuki"
            },
            "age": {
                "N": "10"
            }
        }
    ],
    "Count": 2,
    "ScannedCount": 2,
    "ConsumedCapacity": null
}
AWS CLI DynamoDB