DynamoDB and user table

I created an application, and currently it has a pretty standard user table:

int id, email varchar, password varchar

If I were to switch this to DynamoDB, then how do I create this table?

If I use a hash key with an email address, then I will not be able to offer the ability to update your email, and if I used a hash to store the identifier, then I would need to use a scan that is expensive and limited to a 1 Mb limit.

Any advice please? Thanks Mark

+12
amazon-dynamodb
source share
3 answers

You say it would be expensive to use ID as a hash because you need to filter by email?

If you need to filter your queries with a non-character column, you often end up creating an index for it.

DynamoDB does not have a built-in secundary index , but it is quite simple to implement your own solution.

The main table can use ID as a hash , as you indicated, and the other table will serve as an index, it could be:

varchar email, int id 

Be an email hash key for the secundary table. If it is allowed to have multiple users with the same email address that you can use the ID as a range to make something easier, otherwise a simple column will match.

+6
source share

Having another table for indexing will result in high service. I came across a redundant model of my former director of technical translation.

For your table: USER

RDBMS:

id password email

1, senthil3569 @ stack.com, asks

DynamoDB:

KEY, id, email, password

1, 1, senthil3569@stack.com, asks

senthil3569 @ stack.com, 1, senthil3569@stack.com, asks

Instead of saving a single record, you back up using non-indexed columns.

We hope that the solution is clear.

+2
source share

Create a User table with a hash key identifier (user UUID) and other attributes. Create a global secondary index with the hash key Email, and you have the opportunity to choose a sort key according to your requirements (user status is active, user type).

  • you can get them and update the user by UUID (user ID)
  • Get user with emailId
  • Get a user with active status without a filter (by sort key)
 UserTable: Type: AWS::DynamoDB::Table Properties: TableName: UserTable AttributeDefinitions: - AttributeName: id AttributeType: S - AttributeName: email AttributeType: S - AttributeName: status(optional sort key according to your requirement) AttributeType: S KeySchema: - AttributeName: id KeyType: HASH ProvisionedThroughput: ReadCapacityUnits: 5 WriteCapacityUnits: 5 GlobalSecondaryIndexes: - IndexName: UserDetail KeySchema: - AttributeName: email KeyType: HASH - AttributeName: status(option) KeyType: RANGE Projection: ProjectionType: ALL ProvisionedThroughput: ReadCapacityUnits: 5 WriteCapacityUnits: 5 
0
source share

All Articles