Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Step 3: Read data from a table
In this step, you'll read back one of the items that you created in Step 2: Write data to a table using the console or Amazon CLI. You can use the DynamoDB console or the Amazon CLI to read an item from the Music
table by specifying Artist
and SongTitle
.
For more information about read operations in DynamoDB, see Reading an item.
Follow these steps to read data from the Music
table using the
DynamoDB console.
Open the DynamoDB console at
https://console.amazonaws.cn/dynamodb/.
-
In the left navigation pane, choose Tables.
-
On the Tables page, choose the Music table.
-
Choose Explore table items.
-
On the Items returned section, view the list of items stored in the table, sorted by Artist
and SongTitle
. The first item in the list is the one with the Artist named Acme Band and the SongTitle PartiQL Rocks.
The following Amazon CLI example reads an item from the Music
. You can
do this either through the DynamoDB API or PartiQL, a SQL-compatible query
language for DynamoDB.
- DynamoDB API
-
The default behavior for DynamoDB is eventually consistent reads.
The consistent-read
parameter is used below to
demonstrate strongly consistent reads.
Linux
aws dynamodb get-item --consistent-read \
--table-name Music \
--key '{ "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"}}'
Windows CMD
aws dynamodb get-item --consistent-read ^
--table-name Music ^
--key "{\"Artist\": {\"S\": \"Acme Band\"}, \"SongTitle\": {\"S\": \"Happy Day\"}}"
Using get-item
returns the following sample
result.
{
"Item": {
"AlbumTitle": {
"S": "Songs About Life"
},
"Awards": {
"S": "10"
},
"Artist": {
"S": "Acme Band"
},
"SongTitle": {
"S": "Happy Day"
}
}
}
- PartiQL for DynamoDB
-
Linux
aws dynamodb execute-statement --statement "SELECT * FROM Music \
WHERE Artist='Acme Band' AND SongTitle='Happy Day'"
Windows CMD
aws dynamodb execute-statement --statement "SELECT * FROM Music WHERE Artist='Acme Band' AND SongTitle='Happy Day'"
Using the PartiQL Select
statement returns the
following sample result.
{
"Items": [
{
"AlbumTitle": {
"S": "Songs About Life"
},
"Awards": {
"S": "10"
},
"Artist": {
"S": "Acme Band"
},
"SongTitle": {
"S": "Happy Day"
}
}
]
}
For more information about reading data with PartiQL, see PartiQL select
statements.
To update the data in your table, proceed to Step 4: Update data in a table.