Step 2: Write data to a table using the console or Amazon CLI - Amazon DynamoDB
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 2: Write data to a table using the console or Amazon 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.amazonaws.cn/dynamodb/.

  2. In the left navigation pane, choose Tables.

  3. On the Tables page, choose the Music table.

  4. Choose Explore table items.

  5. In the Items returned section, choose Create item.

  6. On the Create item page, do the following to add items to your table:

    1. Choose Add new attribute, and then choose Number.

    2. For Attribute name, enter Awards.

    3. Repeat this process to create an AlbumTitle of type String.

    4. Enter the following values for your item:

      1. For Artist, enter No One You Know.

      2. For SongTitle, enter Call Me Today.

      3. For AlbumTitle, enter Somewhat Famous.

      4. For Awards, enter 1.

  7. Choose Create item.

  8. 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.

  9. 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 Amazon 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

Linux

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"}}'

Windows CMD

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

Linux

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'}"

Windows CMD

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.