How to do it...

In this recipe, you will create a DyanamoDB table to hold user account records, and you will add a global secondary index (GSI) to allow fast lookups by email address. GSIs give you an additional way to sort the data in your table, which allows for some degree of design flexibility after the table has been created:

  1. Log in to your account and go to the DynamoDB dashboard. Click Create table.
  2. Give the table a unique name and then enter UserID as the Partition key. A primary key in DynamoDB is either a partition key by itself or the combination of a partition key and a sort key. In this case, we will leave the sort key blank:

Create DynamoDB table
  1. Uncheck Use default settings.
  2. For Read-write capacity mode, choose On-demand. This will keep costs low while not using the table and enables rapid auto-scaling to meet increased demand. This should be your default choice for any unpredictable workload that does not have a relatively steady access pattern.
  3. Leave the other settings as defaults and click Create.
  4. It can take a few minutes for your table to become available. Once it does, go to the Items tab and click Create item.
  5. Note that, unlike a relational database, there is no structure for the item beyond the UserID. Enter a unique value for UserID:

Create item
  1. Click the + and enter a few more values, such as EmailAddress and LastName. With DynamoDB, each record can have unique property names, which allows for some very flexible design patterns. Save the record.
  2. Create a new item and this time, give it different properties, such as Username and FullName.

 

  1. In the item summary, note how each of the unique column names you have used is visible, but don't let this fool you—each record only knows about the properties that were assigned to it. This is not a relational database schema. One of the benefits of DynamoDB is the ability to define new properties at runtime without the need to run Data Definition Language (DDL) commands as you would with an RDBMS:

Item summary
  1. Click on the Indexes tab, then click Create index.

 

  1. Enter EmailAddress as the Partition key and click Create index. Leaving the Projected attributes as the default of All means that all properties will be available when looking up items by the index key:

Creating an index
  1. Wait a few minutes for the index to be created. The status will change to Active when the index is ready.
  2. Go back to the Items tab and refresh the page so that the new index is recognized.
  3. Change Scan to Query and select your new index. Enter an email address to match one of your earlier entries into the table and click Start search:

Querying an index
  1. Note that the record only displays the columns that are actually entered on that item. By querying the index, you will get a response back in milliseconds, even if the table had millions or billions of records.
  2. Take some time to explore the other tabs and see the many configuration options available to you.
  3. Be sure to delete the table when you are finished with this recipe, to prevent future charges.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset