Ex:Model a Player

This exercise is based on a question that was asked by a user on Reddit. Please read through the question.

reddit-question.png

Read thread on Reddit

Tasks

1. Decide on which option you would go with & why?

  • Aurora (Relational Datababase)
  • DynamoDB

2. Create a model in NoSQL Workbench to address following access patterns

  1. Search player by name
  2. Search player by ID
  3. Get player’s status

3. (Optional) Deploy the model in Local DynamoDB and try out the access pattern

Solution

1. Read the blog

Open blog

2. Import the model from project repository

  • Open NoSQL Workbench
  • Import model from project repository modeling/reddit-game-player-status.json

3. Commit model to local DynamoDb & try out the queries

  • Commit the model to Local DynamoDB

  • Access Pattern : Get player information by name

aws dynamodb query \
  --table-name  GamePlayers \
  --key-condition-expression '#name = :name' \
  --expression-attribute-names '{"#name":"name"}' \
  --expression-attribute-values '{":name": {"S":"paul"}}' \
  --endpoint-url http://localhost:8000
  • Access Pattern : Get player information by id
    • Notice the use of GSI_Inverted index
aws dynamodb query \
  --table-name  GamePlayers \
  --index-name  GSI_Inverted \
  --key-condition-expression '#id = :id' \
  --expression-attribute-names '{"#id":"id"}' \
  --expression-attribute-values '{":id": {"N":"100"}}' \
  --endpoint-url http://localhost:8000
  • Access Pattern : Get status on name or id
aws dynamodb query \
  --table-name  GamePlayers \
  --index-name  GSI_Inverted \
  --key-condition-expression '#id = :id' \
  --expression-attribute-names '{"#id":"id", "#status":"status"}' \
  --expression-attribute-values '{":id": {"N":"100"}}' \
  --projection-expression '#status' \
  --endpoint-url http://localhost:8000