Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a valid dynamodb key-condition-expression for the cli

Could somebody please tell me what a valid key condition expression would be. I am trying to run a query on a simple table called MyKeyTable. It has two "columns," namely Id and AnotherNumberThatICareAbout which is of type Long.

I would like to see all the values I put in. So I tried:

aws dynamodb query --select ALL_ATTRIBUTES --table-name MyKeyTable
--endpoint http://localhost:8000 
--key-condition-expression "WHAT DO I PUT IN HERE?"

What hash do I need to put in? The docs are a bit lame on this imho. Any help appreciated, even if it's just a link to a good doc.

like image 946
Mark Dickinson Avatar asked Feb 15 '16 14:02

Mark Dickinson


People also ask

What is condition expression in DynamoDB?

In Amazon DynamoDB, you use expressions to denote the attributes that you want to read from an item. You also use expressions when writing an item to indicate any conditions that must be met (also known as a conditional update), and to indicate how the attributes are to be updated.

What is key condition expression?

Key condition expressions for query. To specify the search criteria, you use a key condition expression—a string that determines the items to be read from the table or index. You must specify the partition key name and value as an equality condition. You cannot use a non-key attribute in a Key Condition Expression.

What data types are valid for primary key of a DynamoDB table?

Each primary key attribute must be a scalar (meaning that it can hold only a single value). The only data types allowed for primary key attributes are string, number, or binary. There are no such restrictions for other, non-key attributes.


1 Answers

Here's a command-line-only approach you can use with no intermediate files.

First, use value placeholders to construct your key condition expression, e.g.,

--key-condition-expression "Id = :idValue"

(Don't forget the colon prefix for placeholders!)

Next, construct an expression-attribute-values argument. Note that it expects a JSON format. The tricky bit I always try to forget with this is that you can't just plug in 42 for a number or "foo" for a string. You have to tell DynamoDb the type and value. Ref AWS docs for the complete breakdown of how you can format the value specification, which can be quite complex if you need it to be.

For Windows you can escape quotation marks in it by doubling them, e.g.,

--expression-attribute-values "{"":idValue"":{""N"":""42""}}"

For MacOS/Linux, single quote is required around the JSON:

--expression-attribute-values '{":idValue":{"N":"42"}}'
like image 166
Rick Riensche Avatar answered Sep 20 '22 06:09

Rick Riensche