Create a DynamoDB Table Using the AWS Console
Start course
3h 3m

This course provides detail on the AWS Database services relevant to the AWS Certified Developer - Associate exam. This includes Amazon RDS, Aurora, DynamoDB, MemoryDB for Redis, and ElastiCache.

Want more? Try a lab playground or do a Lab Challenge!

Learning Objectives

  • Obtain a solid understanding of the following Amazon database services: Amazon RDS, Aurora, DynamoDB, MemoryDB for Redis, and ElastiCache
  • Create an Amazon RDS database
  • Create a DynamoDB database
  • Create an ElastiCache cluster

The simplest way to create a DynamoDB table is using the AWS Console. The console provides us the ability to examine the features of DynamoDB, so we'll get started with that. However, the most common way to create a DynamoDB table is using a script that leverages the command line interface or one of the software developer's kit to automate the definition and populate the table with actual datasets. Let's create a table using the following structure. For the table name, we can use music catalog. We discussed using the partition key of artist and the use of song number as the sort key in order to create a unique combination for each item in the table. Please note how the song number and the year need to be defined as attributes of type number. The other attributes will be of type string. To create a DynamoDB table using the console, we navigate to the DynamoDB landing page and then select the 'Create Table' button. 

For any given table, we need to provide a table name, a partition key and an optional sort key. It's also important to provide the required type for these attributes. In addition, there are some table settings that need definition. In this case, please note that the capacity mode, read capacity, write capacity, and auto scaling are predefined as default settings. You can always adjust these later if needed. If you select the Customize Settings panel, you will see how DynamoDB tables can be defined as a standard class type table or a standard infrequent access class table. The standard access class is the most commonly used. The infrequent access class, as the name suggests, is used for rarely accessed data and it's intended to save you some expenses that otherwise could not be realized. Also, please keep in mind that all user data stored in Amazon DynamoDB is fully encrypted at rest. 

By default, DynamoDB manages the encryption key and you're not charged any fee for using it. You can select how the encryption key is managed, but you cannot disable the encryption. Based on our prior discussion, we noticed that a local secondary index will not be useful because of the choices we made in modeling our data, and in general a local secondary index behaves as an alternate sort key while keeping the partition key the same as the core table. 

In this panel, we can implement two global secondary indexes where we have the partition key for album and keep the sort key as the song number. We can also create a second global secondary index using a partition key of genre and keep a sort key of song number. In graphical form, our data will look as shown. Let's create a table using the following structure. It is important to note that a global secondary index basically generates a second table for you and you can decide which attributes are copied to the new table by choosing attribute projections. For that same reason, creating a Global Secondary Index also entails provisioning its own capacity. 

By default, the Global Secondary Index capacity gets defined to be the same as the core tables. However, you can always change this setting. Another detail worth noting is that you can always create and delete a Global Secondary Index any time. These lens global secondary indexes to be used in what the documentation calls Sparse Indexes which are basically infrequently used queries where you can create a global secondary index with all required projections, run the query, and once complete, you can delete the global secondary index. 

This can save you time and can save you money when compared to having to model for a rare query and have it tied to the table all the time. Creating a DynamoDB table using the AWS console, you will see that the table is reported as being created until finally it becomes active for use. Please note that we just created the table, it has no data stored just yet. Creating a table and then populating that table with actual data using the console most likely will require multiple steps. From the actions menu, we can select 'Create Item' to begin adding data to our table. 

Once again, and for this example, we use the data set on display representing a music catalog. Creating an item using the console requires for you to add the attributes in addition to the partition and the sort key. You can also use the DynamoDB   JSON format to enter an item with all its attributes. The resulting process is tedious and for large data sets, you will want to use some form of scripting and automation. Anything more than a handful of items is probably best to pursue using a script or leveraging one of the software developer's kit. Using a script via the CLI or a code via SDK will provide you more reliable and efficient results, however, if you're new to DynamoDB creation, then the AWS console provides a convenient way to explore the different features provided by the service, as well as point you to documentation for additional information.


About the Author
Learning Paths

Stuart has been working within the IT industry for two decades covering a huge range of topic areas and technologies, from data center and network infrastructure design, to cloud architecture and implementation.

To date, Stuart has created 150+ courses relating to Cloud reaching over 180,000 students, mostly within the AWS category and with a heavy focus on security and compliance.

Stuart is a member of the AWS Community Builders Program for his contributions towards AWS.

He is AWS certified and accredited in addition to being a published author covering topics across the AWS landscape.

In January 2016 Stuart was awarded ‘Expert of the Year Award 2015’ from Experts Exchange for his knowledge share within cloud services to the community.

Stuart enjoys writing about cloud technologies and you will find many of his articles within our blog pages.