Search code examples
androidamazon-dynamodbamazon-cognitoaws-mobilehub

How to design primary key for DynamoDB with 3 attributes


I am new to DDB, but from what I understand, The DynamoDBHashKey is the same as the partition key, and the DynamoDBRangeKey is the same as the sort key. However, I have 3 values that I need to make a unique key. This is for a mobile application. The use case is storing records. See below:

@DynamoDBTable(tableName = "foo")
public class Foo {
    private String userID; // Set on a per-device basis by AWS Cognito
    private String name;   // The user's name. There can be many users on a device
    private long time;     // The time the record is created

}

So my original though was to make userId the partition/hash key and name the sort/range key, but each of those combinations will have multiple records, thus the addition of the time attribute. Is there a solution here that I am missing?


Solution

  • Here you go..

    Parttionkey userid-name rangekey time

    Key point here is that partition key is a concatenated key consisting of two identifiers