100 - My first table

In this lab you will experiment the Amazon DynamoDB, by creating a table, and inserting and retrieving data from it.


Prerequisites

For this lab you just need to have your AWS CLI properly configured, or execute this lab from a Cloud9 or EC2 Instance using a role with permissions to operate over DynamoDB.

Context

As your first taste of Amazon DynamoDB, you will create a table, insert a record, and query it.

If you are running this lab in a single-account/multiple users environment, don’t forget to add a <prefix> to the name of the resources that you are creating.


Task 1. Create a table using the AWS console.

  1. Go to the DynamoDB home: https://console.aws.amazon.com/dynamodb.
  2. Click on Create table.
  3. For Table name, type <prefix>Product.
  4. For Primary key*, type Id.
  5. For Table Settings, use default settings.
  6. Click on Create.
  7. Wait for the table to be created.


Task 2. Insert a record.

  1. Select the tab Items and click on Create item.
  2. The pop up window Create item will be shown. Select the option Text.
  3. Fill in the details as shown below
{
  "Id": "PRD01",
  "Description": "UNICORN GENERATOR",
  "LatestStockUpdate": "2019-10-22T22:15:34Z",
  "Suppliers": [
    "S045",
    "S4456",
    "ACME126"
  ]
}
  1. Click on Save.

Task 3. Use AWS CLI to query the table.

  1. Get back to the console on your computer or on Cloud9.
  2. Let’s check if the table is there. Be sure of using the correct region.
    aws dynamodb list-tables
    

    You should get a response similar to this one

    {
        "TableNames": [
            "Product"
            ...
        ]
    }
    

Other tables may appear there if you have other tables on your account, in that particular region.

  1. Access the console and submit the query using the AWS CLI. You will need to specify the region for the table.
    aws dynamodb get-item --table-name Product --key '{"Id" : { "S":"PRD01"}}'
    

    and the response should be similar to the following:

    {
        "Item": {
            "LatestStockUpdate": {
                "S": "2019-10-22T22:15:34Z"
            }, 
            "Id": {
                "S": "PRD01"
            }, 
            "Suppliers": {
                "L": [
                    {
                        "S": "S045"
                    }, 
                    {
                        "S": "S4456"
                    }, 
                    {
                        "S": "ACME126"
                    }
                ]
            }, 
            "Description": {
                "S": "UNICORN GENERATOR"
            }
        }
    }
    

Finishing the lab

You have finished this lab.

Deleting the table that you just created will clean your account with respect to this lab.

Lab Author: Fabian Da Silva