Aws DynamoDb
Creating and querying a new table.
When creating a Table and defining your DynamoDB schema, one of the first options you’ll be asked is to specify your Table’s Partition Key and Sort Key. This is an important decision that has impact on how your table’s record’s can be accessed.
A DynamoDB Partition Key has to do with DynamoDB’s internal physical storage structure. The partition key is the attribute that DynamoDB will use to partition your data onto one of its many storage nodes.
This is part of the reason DynamoDB is so scalable. Because it can hash your data inputs into an arbitrary number of storage nodes, it can easily scale up to increased demands by simply adding a new partition and shifting data around.
A Sort Key is a secondary key that you can optionally decide to use alongside your Partition Key. In other words, your traditional Primary Key can be either just a Partition Key, or a Partition Key + a Sort Key.
A Partition Key and Sort Key combination is known as a composite primary key.
With a Partition Key, you can store records with the same partition key value but a different sort key value. All records with the same partition key value are stored together on the same data storage node.
Let’s create a new table in DynamoDb.
Press the create table button.
Type UserGameHistory in the textbox name. Type userId as partition key. String. Type lastDatePlayed in the textbox sort key. Number.
Press create table.
Well, now we have the new table named UserGameHistory.
Select the table and create a new item.
Type “12345” in the userId field and type “1619156406” in the timestamp field. Unix Timestamp is a value that convert a date in a number. You can find the right explain here. https://www.epochconverter.com/
Now add a new attribute as a string.
Type the attribute “gameId” and type “9875” as value. Add a new attribute as a string.
Type the attribute “preferredLanguage” and type “english” as value. Add a new attribute as a list.
Type the attribute “supportedGameTypes” and insert a string field.
Insert “SinglePlayer” and then “MultiPlayer”.
Insert a new attribute named “lastStopTime” as number and type “90” as value.
Save changes. In “Explore Items” select the table “UserGameHistory”. In the Scan or Query Items, select “Query”. In the “userId” partition key type “12345” and in the “lastDatePlayed” sort key select “greater than” and type “1609477200”.
Now run the query.