Managing Data Relationships in DynamoDB

45 minutes
  • 7 Learning Objectives

About this Hands-on Lab

In this lab, we will create a data model in DynamoDB to manage one-to-one, one-to-many, many-to-many, and hierarchical data relationships.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Analyze Provided Data

Use target_abridged.csv to plan your data model to satisfy the provided access patterns by choosing partition and sort keys for your DynamoDB table, any data transformations, and any secondary indexes that are needed.

Create a DynamoDB Table

With the information from the previous task, create a DynamoDB table in the provided AWS account.

Log in to Provided EC2 Instance

Log in to the provided EC2 instance with the credentials found in the lab interface:

ssh cloud_user@<PUBLIC_IP_ADDRESS>
Update `load.py`

Update load.py to execute any data transformations from the first task.

Run `load.py`

Run load.py, replacing <TABLE_NAME> with the name of your table:

python3 load.py -t <TABLE_NAME>
Update `queries.py`

Edit queries.py, updating the queries dictionary with the appropriate queries to satisfy each access pattern. Be sure to use the correct table and index names.

Confirm Queries Return Expected Data

Run queries.py:

python3 queries.py

Verify output against the expected output in the lab information.

Additional Resources

We have been tasked with creating a DynamoDB table that models data about Target stores in the United States. We will need to examine the data in the context of the access patterns listed below. We will then create a DynamoDB table with the necessary partition and sort keys, as well as secondary indexes to facilitate our access patterns. We will need to modify the provided load.py script to make any needed data transformations or mutations. We will then load the data into our table utilizing load.py. And finally, we will modify queries.py to test our access patterns against our DynamoDB table.

Access Patterns

Given ID, return all attributes for store (ID: 1957).

Return all stores that do not observe daylight savings time; return just state and store ID.

Given a phone area code, return all stores with formatted addresses and phone numbers (Area Code: 206).

Return all attributes for all stores with Starbucks and CVS.

Given state, return all attributes for all stores (State: WA).

Given state and city, return all attributes for all stores (State: WA; City: Seattle).

Given state city and zip, return all attributes for all stores (State: WA; City: Seattle; Zip: 98125).

Expected Returns

Query ID returned 1 items with an average of 48 attributes

Query DaylightSavingsNo returned 54 items with an average of 3 attributes

Query PhoneArea returned 4 items with an average of 5 attributes

Query StarbucksCVS returned 816 items with an average of 47 attributes

Query State returned 37 items with an average of 47 attributes

Query StateCity returned 3 items with an average of 48 attributes

Query StateCityZip returned 1 items with an average of 48 attributes

Resources

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?