Step 2: Write Data to a Table Using the Console or AWS CLI - Amazon DynamoDB

Step 2: Write Data to a Table Using the Console or AWS CLI

In this step, you insert several items into the Music table that you created in Step 1: Create a Table.

For more information about write operations, see Writing an Item.

Follow these steps to write data to the Music table using the DynamoDB console.

  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. In the table list, choose the Music table.

    
                                Console screenshot showing the Tables view with a Music
                                    table.
  4. Select View Items.

    
                                Console screenshot showing the View items button in the
                                    table view.
  5. In the Items view, choose Create item.

    
                                Console screenshot showing the Music table and the Create
                                    item button.
  6. Choose Add new attribute, and then choose Number. Name the field Awards.

    
                                Console screenshot showing the Add new attribute
                                    list.
  7. Repeat this process to create an AlbumTitle of type String.

  8. Enter the following values for your item:

    1. For Artist, enter No One You Know as the value.

    2. For SongTitle, enter Call Me Today.

    3. For AlbumTitle, enter Somewhat Famous.

    4. For Awards, enter 1.

  9. Choose Create item.

    
                                Console screenshot showing the completed fields for the
                                    item.
  10. Repeat this process and create another item with the following values:

    1. For Artist, enter Acme Band.

    2. For SongTitle enter Happy Day.

    3. For AlbumTitle, enter Songs About Life.

    4. For Awards, enter 10.

  11. Do this one more time to create another item with the same Artist as the previous step, but different values for the other attributes:

    1. For Artist, enter Acme Band.

    2. For SongTitle enter PartiQL Rocks.

    3. For AlbumTitle, enter Another Album Title.

    4. For Awards, enter 8.

The following AWS CLI example creates several new items in the Music table. You can do this either through the DynamoDB API or PartiQL, a SQL-compatible query language for DynamoDB.

DynamoDB API
aws dynamodb put-item \ --table-name Music \ --item \ '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Somewhat Famous"}, "Awards": {"N": "1"}}' aws dynamodb put-item \ --table-name Music \ --item \ '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Howdy"}, "AlbumTitle": {"S": "Somewhat Famous"}, "Awards": {"N": "2"}}' aws dynamodb put-item \ --table-name Music \ --item \ '{"Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"}, "AlbumTitle": {"S": "Songs About Life"}, "Awards": {"N": "10"} }' aws dynamodb put-item \ --table-name Music \ --item \ '{"Artist": {"S": "Acme Band"}, "SongTitle": {"S": "PartiQL Rocks"}, "AlbumTitle": {"S": "Another Album Title"}, "Awards": {"N": "8"} }'
PartiQL for DynamoDB
aws dynamodb execute-statement --statement "INSERT INTO Music \ VALUE \ {'Artist':'No One You Know','SongTitle':'Call Me Today', 'AlbumTitle':'Somewhat Famous', 'Awards':'1'}" aws dynamodb execute-statement --statement "INSERT INTO Music \ VALUE \ {'Artist':'No One You Know','SongTitle':'Howdy', 'AlbumTitle':'Somewhat Famous', 'Awards':'2'}" aws dynamodb execute-statement --statement "INSERT INTO Music \ VALUE \ {'Artist':'Acme Band','SongTitle':'Happy Day', 'AlbumTitle':'Songs About Life', 'Awards':'10'}" aws dynamodb execute-statement --statement "INSERT INTO Music \ VALUE \ {'Artist':'Acme Band','SongTitle':'PartiQL Rocks', 'AlbumTitle':'Another Album Title', 'Awards':'8'}"

For more information about writing data with PartiQL, see PartiQL Insert Statements.

For more information about supported data types in DynamoDB, see Data Types.

For more information about how to represent DynamoDB data types in JSON, see Attribute Values.

After writing data to your table, proceed to Step 3: Read Data from a Table.