Step 5: Query Data in a Table - Amazon DynamoDB

Step 5: Query Data in a Table

In this step, you query the data that you wrote to the Music table in Step 2: Write Data to a Table Using the Console or AWS CLI by specifying Artist.

For more information about query operations, see Working with Queries in DynamoDB.

Follow these steps to use the DynamoDB console to query data in the Music table.

  1. Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/.

  2. In the navigation pane on the left side of the console, choose Tables.

  3. Choose the Music table from the table list.

  4. Choose the Items tab for the Music table.

  5. In the drop-down list, choose Query.

    
                                Console screenshot showing the dropdown list with Query
                                    selected on the Items tab.
  6. For Partition key, enter Acme Band, and then choose Start search.

    
                                Console screenshot showing the completed query fields for
                                    the Music table.

The following AWS CLI example queries an item in the Music table using query.

aws dynamodb query \ --table-name Music \ --key-condition-expression "Artist = :name" \ --expression-attribute-values '{":name":{"S":"Acme Band"}}'

Using query returns the following sample result.

{ "Count": 1, "Items": [ { "AlbumTitle": { "S": "Updated Album Title" }, "Awards": { "N": "10" }, "SongTitle": { "S": "Happy Day" }, "Artist": { "S": "Acme Band" } } ], "ScannedCount": 1, "ConsumedCapacity": null }

To create a global secondary index for your table, proceed to Step 6: Create a Global Secondary Index.