Home > Enterprise >  How to get list of all items in a dynamo Table using aws cli
How to get list of all items in a dynamo Table using aws cli

Time:02-03

I need to get the list of all items under Platform key in a certain Dynamodb Table called JKOwner using AWS CLI. This is what I'm currently trying to test:

aws dynamodb get-item --table-name JKOwner --key '{"Platform": {"S": "GOVTEST"}}'

Using this cli command, I am able to get the item GOVTEST under the Platform key. But what command should I use if I need to get all items aside from GOVTEST so I could store it in a variable? There are around 200 Platform values which I need to get into the list. The details of the item doesn't really matter as of now. Thanks in advance for your help.

CodePudding user response:

Have you tried?

aws dynamodb query 
  --table-name JKOwner
  --key-condition-expression "Platform = :v1" 
  --expression-attribute-values "{ \":v1\" : { \"S\" : \"GOVTEST\" } }" 

CodePudding user response:

If you truly need to get all items, you should use a Scan operation. Then you use a filter expression to omit items where platform = GOVTEST items.

If you want to make it really easy on yourself, you could use PartiQL for DynamoDB and do something like:

SELECT * FROM JKOwner WHERE Platform <> 'GOVTEST'

For an example of doing PartiQL on the command line, look on the PartiQL for DynamoDB tab on this page or do this:

aws dynamodb execute-statement --statement "SELECT * FROM Music   \
                                            WHERE Artist='Acme Band' AND SongTitle='Happy Day'"
  •  Tags:  
  • Related