Design a Database for a Mobile App

with Amazon DynamoDB

Module 1: Background and setup

To get started, you will learn how to model your DynamoDB table to handle all of the access patterns in your application

Background and Setup

Imagine you are building a mobile application to upload photos. Users will upload photos through your application, and friends can view their photos.

Your application is a social application, so users will want to find and follow friends. By following a friend, a user will receive notifications of the friend’s new photos and be able to message the friend.

When using your application, users will want to browse all photos for a particular user, starting with the most recent photo.

Finally, users can react to a photo with one of four emojis — a heart, a smiley face, a thumbs up, or a pair of sunglasses. When looking at a photo, users should be able to see the number of each type of reaction a photo has received.

In this lab, you will learn how to model your DynamoDB table to handle all of the access patterns in your application. The following modules will show you some core data modeling strategies, as well as using the new transactions feature, to use DynamoDB in a fast, performant way.

In the steps in this module, you will configure your environment and download the code to follow along during the lab.

 Time to Complete

20 minutes

 Services Used

Implementation

  • Use a personal AWS account or create a new AWS account for this lab. Do not use an organizational account so that you have full access to the necessary services and do not leave behind any resources from the lab. If you do not delete the resources used in this lab when you are finished, you may incur AWS charges.

  • AWS Cloud9 is a cloud-based integrated development environment (IDE) that lets you write, run, and debug code with just a browser. AWS Cloud9 includes a code editor, debugger, and terminal. It also comes prepackaged with essential tools for popular programming languages and the AWS Command Line Interface (CLI) preinstalled so that you don’t have to install files or configure your laptop for this lab. 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.

    To set up your AWS Cloud9 development environment:

    1. Navigate to the AWS Management Console, choose Services at the top of the page, and then choose Cloud9 under Developer Tools.
    2. Choose Create environment.
    3. Type DynamoDB Quick Photos in the Name box.
    4. Choose Next step.
    5. Leave the Environment settings at their defaults to create a new t2.micro EC2 instance, which will be hibernated after 30 minutes of inactivity.
    6. Choose Next step.
    7. Review the environment name and settings, and choose Create environment. Your environment will be provisioned and prepared after several minutes.
    8. Once ready, your IDE should open with a welcome note.

    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 IDE, this is where you run commands to execute code samples.
    AWS Cloud9 Console
  • In this lab, you will use Python scripts to interact with the DynamoDB API. Run the following commands in your AWS Cloud9 terminal to download and unpack the module code.

    cd ~/environment
    curl -sL https://s3.amazonaws.com/ddb-labs/quick-photos.tar | tar -xv

    Run the following command in your AWS Cloud9 terminal to view your directories

    ls

    You should see two directories in the AWS Cloud9 file explorer:

    • application: The application directory contains example code for reading and writing data in your table. This code is similar to code you would have in your real mobile application backend.
    • scripts: The scripts directory contains administrator-level scripts, such as for creating your table, adding a secondary index, or deleting your table.

Conclusion

In this module, you learned about the example application you build in this lab. You also set up an AWS account and configured an AWS Cloud9 instance.

You are now ready to start the lab. With DynamoDB, it is important to plan your data model up front so that you have fast, consistent performance in your application. In the next module, you learn about planning your data model.

Was this page helpful?

Plan Your Data Model