Creating a DynamoDB Table with Local and Global Secondary Indexes
Lab Steps
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:
2. Enter the following in the Table details section:
- Table name:
- Partition key:
- Name: Enter
- Type: Select
- Sort key:
- Name: Enter
- Type: Select
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:
5. Scroll down to the Secondary indexes section and click Create local index:
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
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:
8. Scroll to the bottom and click Create table.
After roughly 30 seconds, you will see that the table has become active:
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
- Type: Select
- Sort key:
- Name: Enter
- Type: Select
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
13. Scroll down to the Secondary indexes section, and click Create global index:
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
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
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.