Creating a DynamoDB Table inside the AWS Console

Hands-On Lab

 

Photo of Fernando Medina Corey

Fernando Medina Corey

Training Architect

Length

00:30:00

Difficulty

Beginner

In this activity we'll look at how we can create DynamoDB tables in the console to use in our Fullstack Serverless Applications. We will create our own table as well as interact with an existing table in the AWS console.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

DynamoDB Console Lab

In this lab, we are working for the company PrometheonPartners. We are tasked with updating the attributes of an AWS table in the Dynamo DB as well as creating a new table.

Open a Table

To begin, we need to sign in to the AWS Console. Once logged in, go to the Database section and select DynamboDB. In this section, select the Tables on the left side of the screen. A list of tables will appear. We are working with the PrometheonPartners table.

Note that this table is used only to demo items and is preloaded with information. When used in later labs, the information you add here during this lab may not appear.

Perform a Query

Once we've opened the table, select the Items tab. Here, we can perform a query to find specific items in the table. At the top of the page, where it says Scan, use the dropdown arrow to change Scan to Query.

The main search criteria is the Partition Key. For our example, search for ProTowTires. Note that a query is case sensitive.

After entering in the value, select Start search. The table will return with information over ProTowTires.

Edit an Attribute

With ProTowTires pulled up, we can update the information. Right now, the clientDealValue isn't actually a value, but a general idea of what the value is. To change the value, select the clientDealValue value so that the cursor appears. Change the clientDealValue to something over 9000; for instance, 9500.

Another way to edit the attribute is to select ProTowTires from the items list. All attributes appear, and all of them are editable from this screen. Go ahead and update the strings however you wish. Once you've finished updating, select Save. All attributes appear in their updated format.

Create a New Table

Now that we've updated a preexisting table, let's create a new one. There are two ways to create a new table. We can either select Create Table on the Tables page, or go back to the Dashboard page and select Create Table from there.

The table we create is used in later labs, at least in name, but the information in the table changes depending on the lab as you move on.

Name the new table PrometheonMusic. For this table, set the Partition Key as Artist, check off the Add Sort Key box, then set it to SongTitle. These two items always need to be populated when adding items.

Once the keys are populated, uncheck the Use default settings box. Since we are creating a table that will only have a few items, we want to remove setting that will auto-populate or create new table slots.

Uncheck the Read capacity and Write capacity boxes under Auto Scaling. This makes the Read capacity units and Write capacity units in the Provisioned capacity section editable. We want to set them to 5 if they are not already.

Once everything is set up, select Create to make this table.

Add Items to a Table

With our table created, we can start to add in our information. For this table, you can add whatever musical artist and song title you want. For our examples, we will be using Rihanna and songs by her.

To get started, select the Items tab. Then select Create Item. Now, when creating an item, we need to add both an Artist for the partition key and a SongTitle for the sort key. For our example, we'll be using Rihanna as the artist, with the song Work. Once the form is filled out, select Save to add the item to the table.

Add an Attribute to an Item

With the item successfully added, we realize that we forgot to add an extra attribute to the item. To edit it, select the artist to open the item's page. Select the add button, a circle with a plus sign in it, then Append and String. Name the new item CriticRating. In it, make the rating above 9, such as 9.8. Select Save once you are finished adding the item.

Now, let's add a second item. While we will still be using Rihanna, the song title for this one will be Stay. When you create it, note that CriticRating is not an automatic option. As it was not a key created with the table, it will not be required for each item and must be added separately. Add CriticRating to this second item and set its amount to something less than 9, such as a 7 or 8. Select Save once finished.

If you would like, feel free to add more items to the table, though all further examples will only refer to the Rihanna songs used so far.

Query by Key

Now that we've finished entering our items, let's practice using the query. Go up to Scan, and once again use the dropdown to change it to Query. For the partition key, enter Rihanna. In the sort Key section, enter the song title Stay. Remember, the queries are case sensitive!

The item you queried for appears.

Filter a Query

Now, say we have something else we want to search for besides the song title, such as the critic rating. Before starting, make sure only an artist name is entered, no song titles.

In the query window, select Add filter. Name the filter CriticRating, leave it as String, set the search to greater than (>), and then enter a numeric value equal to or lower than a critic rating you gave a song. For our example, we will use 9, as we entered a critic rating of 9.8 when creating our first item.

Rihanna's song Work will appear once the query runs.

Scan a Table

Let's work with a scan this time instead of a query. Scans only need a single filter, and that filter does not have to be one of the keys that is set when creating the table. For this scan, let's use the CriticRating.

Select Add filter and then enter CriticRating as our filter type. Leave it as a string and then set it to search for less than (<) 9. All items with a number value that is less than 9 in the CriticRating section will appear no matter what the Artist or SongTitle is.

Review

Upon completing this lab, you can now create and edit tables in DynamoDB. That, and you now know how to add items, how to edit those items, and perform both scans and queries for different items in your table. Congratulations on completing this lab!