Imagine that you are building an online bookstore application. Your bookstore has a large inventory of books that are stored in your warehouse to be sold to customers. The application must show users the books that are available for sale as well as some basic information about the book, such as its author.

The application needs to retrieve a specific book by its title and author so that a user can drill in for more detail when looking at a book. Furthermore, your application should allow users to browse all books in a particular category, such as history or biography, to allow for discoverability of interesting books.

Finally, you may carry different formats of a book, such as hardcover, paperback, or audiobook. Your application should store the formats you have in stock for a book with a mapping to the item number in your inventory system. Your application should allow these formats to be updated over time, as you may add or remove formats for a book.

In the modules in this tutorial, you learn how to model a DynamoDB table to accommodate these application needs.

In order to complete this tutorial, you need an AWS account and access to create AWS Identity and Access Management (IAM), Amazon DynamoDB, and AWS Cloud9 resources in that account. The step-by-step guide in this tutorial explains how to set up all prerequisites.

Time to Complete Module: 15 Minutes

  • Step 1. Create an AWS account

    Use a personal account or create a new AWS account for this tutorial rather than using an organization’s account to ensure that you have full access to the necessary services and do not leave behind any resources from the tutorial.

  • Step 2. Set up your AWS Cloud9 IDE

    AWS Cloud9 is a cloud-based integrated development environment (IDE) that lets you write, run, and debug code with just a browser. It includes a code editor, debugger, and terminal. Cloud9 comes prepackaged with essential tools for popular programming languages and the AWS Command Line Interface (CLI) preinstalled so that you don’t need to install files or configure your laptop for this tutorial. Your AWS Cloud9 environment will have access to the same AWS resources as the user with which you signed in to the AWS Management Console.

    Take a moment now to setup your AWS Cloud9 development environment.
    1. Navigate to the AWS Management Console, choose Services then choose Cloud9 under Developer Tools.
    2. Choose Create environment.
    3. Type DynamoDB Deep Dive in the Name box and optionally type a Description.
    4. Choose Next step.
    5. Leave Environment settings at their defaults of launching a new t2.micro EC2 instance which will be paused after 30 minutes of inactivity.
    6. Choose Next step.
    7. Review the environment setting and choose Create environment. It will take several minutes for your environment to be provisioned and prepared.
    8. Once ready, your IDE will open to a welcome screen.

    You should now see your AWS Cloud9 environment. There are three areas of the AWS Cloud9 screen to know, as illustrated in the following screenshot:

    • File explorer: On the left side of the screen, this shows a list of the files in your directory.
    • File editor: On the upper right portion of your screen, this is where you view and edit files that you’ve selected in the file explorer.
    • Terminal: On the lower right portion of the screen, this is where you run commands to execute code samples.
    cloud 9 consloe

    (Click to enlarge)

    cloud 9 consloe
  • Step 3. Download the supporting code

    In these modules, you use Python scripts to interact with the DynamoDB API.

    Run the following commands in your AWS Cloud9 terminal to download the scripts and install the application dependencies:

    1. Download and unpack the module code by running the following command in the AWS Cloud9 terminal

    curl -sL | tar -xv

    2. To install Boto 3, run the following command in the AWS Cloud9 terminal.

    sudo pip install boto3

    You are now ready to start this tutorial. In the first module you insert items into and retrieve items from your DynamoDB table.