how to return items in a dynamodb on aws-cli

Amazon Web-ServicesAmazon DynamodbAws Cli

Amazon Web-Services Problem Overview

So, I have a DynamoDB table Users and I want to return all the contents of this table. Or maybe even some.

I tried

aws dynamodb query --table-name Users 

and it says I have to specify key-condition or key-condition-expression, so I added the following:

aws dynamodb query --table-name Users --key-condition-expression Username = "test"

and it returns an error message " Unknown options: test ".

Amazon Web-Services Solutions

Solution 1 - Amazon Web-Services

If you want to dump the whole table, just use

aws dynamodb scan --table-name Users

Solution 2 - Amazon Web-Services

Try this format:

aws dynamodb get-item --table-name Users --key '{"Username": {"S": "test"}}'

Solution 3 - Amazon Web-Services

Since the question is about using the query operation, here it goes.

As the AWS cli documentation explains, you should separate the attribute values from the condition, by using the --expression-attribute-values parameter:

aws dynamodb query --table-name Users 
    --key-condition-expression "Username = :v1" 
    --expression-attribute-values "{ \":v1\" : { \"S\" : \"test\" } }"

Additionally, you may combine more attributes in the filter (in my case I have a Datetime sort key I want to filter by):

aws dynamodb query 
  --table-name Users
  --key-condition-expression "Username = :v1 AND #Datetime BETWEEN :v2 AND :v3" 
  --expression-attribute-names "{ \"#Datetime\": \"Datetime\" }" 
  --expression-attribute-values "{ \":v1\" : { \"S\" : \"test\" }, \":v2\" : { \"S\" : \"2019-06-06\" }, \":v3\" : { \"S\" : \"2019-06-07\" } }" 

Here the #Datetime mapping is done through the --expression-attribute-names parameter, because Datetime is a reserved keyword, so I cannot use it inside the key condition expression.

Solution 4 - Amazon Web-Services

As per my understanding you are not passing "key"(hash or hash/range) properly

create a file containing your keys: test.json

    "userName": {"S": "abc"},
    "anyRangeKey": {"S": "xyz"}  //optional


aws dynamodb get-item --table-name users --key file://test.json

Hope that helps

Solution 5 - Amazon Web-Services

aws dynamodb get-item --table-name ProductCatalog --key "{""Id"":{""N"":""205""}}" --no-verify-ssl


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBennjoe MordenoView Question on Stackoverflow
Solution 1 - Amazon Web-ServicesataylorView Answer on Stackoverflow
Solution 2 - Amazon Web-ServicesAkavallView Answer on Stackoverflow
Solution 3 - Amazon Web-ServicesSebaGraView Answer on Stackoverflow
Solution 4 - Amazon Web-ServicesHarshal BulsaraView Answer on Stackoverflow
Solution 5 - Amazon Web-ServicesKumarvijay WalikarView Answer on Stackoverflow