Creating a DynamoDB Table with Local and Global Secondary Indexes

Lab Steps

lock
Logging in to the Amazon Web Services Console
lock
Creating a DynamoDB Table with a Partition Key
lock
Creating a DynamoDB Table with Local and Global Secondary Indexes
lock
Inserting Items Into a DynamoDB Table
lock
Editing DynamoDB Table Items
lock
Querying a DynamoDB Table
lock
Deleting a DynamoDB Table
Need help? Contact our support team

Here you can find the instructions for this specific Lab Step.

If you are ready for a real environment experience please start the Lab. Keep in mind that you'll need to start from the first step.

Introduction

In the previous lab step, you created a DynamoDB table with a partition key. In this lab step, you will create two new tables. one with a local secondary index and another table with two global secondary indexes.

 

Instructions

1. On the right-hand side of the page, click Create table:

alt

 

2. Enter the following in the Table details section:

  • Table name
  • Partition key:
    • Name: Enter 
    • Type: Select 
  • Sort key:
    • Name: Enter 
    • Type: Select 

alt

 

3. In the Settings section, select Customize settings.

 

4. Under Read/write capacity settings, ensure Provisioned is selected for Capacity mode, and enter the following:

  • Read capacity:
    • Provisioned capacity units
  • Write capacity:
    • Provisioned capacity units

alt

 

5. Scroll down to the Secondary indexes section and click Create local index:

alt

The New local secondary index dialog box will appear.

 

6. Enter the following to configure your local secondary index:

  • Sort Key:
    • Name: Enter 
    • Type: Select 
  • Attribute projections: Select 

alt

An LSI (Local Secondary Index) has the same partition key as the table's primary key and will share the provisioned capacity of the table in contrast to global secondary indexes which provision their own capacity.

 

7. To finish creating the local secondary index, at the bottom, click Create index:

alt

 

8. Scroll to the bottom and click Create table.

After roughly 30 seconds, you will see that the table has become active:

alt

 

In contrast to a Local Secondary Index, a Global Secondary Index is an index with a partition and sort key that can be different from those in the table. It is considered "global" because queries on the index can span all of the data in a table, across all partitions.

 

9. Click Create table once more to start creating another table.

 

10. Enter the following in the Table details section:

  • Table Name
  • Partition key:
    • Name: Enter 
    • TypeSelect 
  • Sort key:
    • Name: Enter 
    • Type: Select 

alt

 

11. In the Settings section, select Customize settings.

 

12. In the Read/write capacity settings section, ensure the Capacity mode is Provisioned, and enter the following:

  • Read capacity:
    • Provisioned capacity units: Enter 
  • Write capacity:
    • Provisioned capacity units: Enter 

alt

 

13. Scroll down to the Secondary indexes section, and click Create global index:

alt

The New global secondary index dialog form will appear.

 

14. Enter the following:

  • Partition key:
    • Name: Enter  
    • Type: Select 
  • Sort key:
    • Name: Enter 
    • Type: Select 
  • Attribute projections: Select 

alt

 

15. To finish creating the global secondary index, at the bottom, click Create index.

 

16. Click Create global index again and enter the following:

  • Partition key:
    • Name: Enter 
    • Type: Select 
  • Sort key:
    • Name: Enter 
    • Type: Select 
  • Attribute projections: Select

alt

 

17. To finish creating the global secondary index, at the bottom, click Create index.

 

18. Scroll to the bottom and click Create table.

Once again, you will see your table created after roughly 30 seconds.

 

Summary

In this lab step, you used the DynamoDB dashboard to create multiple DynamoDB tables with local and global secondary indexes.