0
votes

I want to store a user in DynamoDB. It has an ID, email & password hash.

Both the ID and email will be unique. I want to be able to look up the user object using either the ID or the Email.

How do I both create this table and query/get a user object with just the ID and then again with just the email?

1
Create a Global Secondary Index with email as PK - karjan

1 Answers

0
votes

You describe two access patterns

  1. Fetch user by email
  2. Fetch user by ID

You could support these access patterns by creating a primary key of email in your base table and a global secondary index (GSI) on the user ID (or vice versa). The important point is that the attributes you want to search by are built into your primary key. This will allow you to execute a fast query operation for both of your access patterns.