Working with DynamoDB Local and Global Indexes

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

In this lab, we will explore DynamoDB local and global secondary indexes, and their impact on performance and capacity unit usage.

An existing unindexed table is provided, and we will create a new table with local and global secondary indexes. Load the same dataset into our new table with a provided data loader, then use a test utility to observe the performance and capacity differences when performing read operations against tables with and without indexes.

**Note: Use the `us-east-1` region for this lab.**

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a New Table with Local and Global Secondary Indexes
  • Log in to the AWS Management Console for the lab environment at the provided URL with the supplied credentials.
    Note: Use the us-east-1 region for this lab.
  • Create a new DynamoDB table named album_indexed with a partition key of artist_id and a sort key of id. Add a local secondary index for the format attribute, and create a global secondary index for the title attribute.
Log In to the EC2 instance and Load Data into Your Newly Created Table
  • Log in to the provided EC2 instance with the provided IP and credentials.
  • Run the index_table_load command to load data into your table.
Verify the Table Contents and Test Querying Against the Indexes You Created
  • Return to the AWS Management Console and verify the data has been loaded to the album_indexed table.
  • Test querying against the title and format indexes.
Run the Provided Test Utility and Observe the Results
  • Return to the provided EC2 instance, run the provided pineheadrecords_query command, and observe the results of the scan/filter against the album table and query against the album_indexed table.

Additional Resources

The client our company has a contract with has launched its online vinyl record store. Unfortunately, several read operations are proving slow and expensive after the migration from MySQL to DynamoDB. The company has requested we test the impact of local and global secondary indexes for the dataset. Two operations are particularly problematic, and the development team down the hall has created a test utility that performs the troublesome scan/filter operations against the existing album table. They've also written query functions that are performed against the album_indexed table when it is present, while assuming there is a local secondary index on the format attribute and a global secondary index on the title attribute. The client is hoping the cost and performance of returning all albums of a specific format by a specified artist and returning data from the table by album title will improve through the addition of secondary indexes.

Once the table has been created with the partition key of artist_id and sort key of id, as well as a local secondary index on the format attribute and a global secondary index on the title attribute, we will load data into the table from the provided EC2 instance with the following command:

index_table_load

Then run the provided test utility with the following command:

pineheadrecords_query

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?