Search code examples
amazon-dynamodbaws-cli

How do I query keys starting with underscores with the AWS Dynamo cli?


I have a key starting with underscore and don't know how to query it

aws dynamodb query \
    --table-name mytable \
    --key-condition-expression '_mykey=:xxx' \
    --expression-attribute-values '{ ":xxx": {"S": "somevalue"}}'

An error occurred (ValidationException) when calling the Query operation: Invalid KeyConditionExpression: Syntax error; token: "_", near: "_mykey"

Can I escape it somehow? I tried "/_mykey" and "\_mykey" but doesn't work.


Solution

  • This might be the most awful user experience I've ever had with a tool:

    aws dynamodb query \
        --table-name mytable \
        --projection-expression "#aaa" \
        --expression-attribute-names '{ "#aaa": "_id" }' \
        --key-condition-expression "#aaa=:bbb" \
        --expression-attribute-values '{ ":bbb": {"S": "somevalue"}}'