Introduction to Dynamo DB

What is DynamoDB?

Amazon DynamoDB is a fast and flexible NoSQL database service for all applications thatneed consistent, single-digit millisecond latency at any scale. It is a fully managed database and supports both document and key-value data models. Its flexible data model and reliable performance make it a great fit for mobile, web, gaming, ad-tech, IoT, and many other applications.

DynamoDB is Serverless, can auto scale, integrates well with Lambda, and its a really popular choice with developers and architects designing serverless applications.

  • Stored on SSD storage
  • Spread across 3 geographically distinct data centers
    • avoids any single point of failure
  • Choice of 2 consistency models:
    • Eventual Consistent Reads (default)
      • Consistency across all copies of data is usually reached within a second.
      • Repeating a read after a short time should return the updated date *
      • Best Read Performance
    • Strongly Consistent Reads
      • A strongly consistent read returns a result that reflects all writes that received a successful response prior to the read
        • all successful writes will be read consistently across all 3 locations
  • Tables
  • Items (think of a row of data in a table)
  • Attributes (Think of a column of data in a table)
  • Supports key-value and document data structures
  • Key = The name of the data, Value = the data itself
    • userid = "123123123"
  • Documents can be written in JSON, HTML, or XML

DynamoDB - Primary Keys

  • DynamoDB stores and retrieves data based on a Primary Key
  • 2 types of Primary Key:
    • Partition Key - unique attribute (e.g. user ID)
      • Value of the Partition key is input to an internal hash function which determines the partition or physical location on which the data is stored
      • If you are using the Partition Key as your Primary Key, then no two items can have the same Partition Key
    • Composite Key (Partition key + Sort Key) in combination
      • use when partition key is not necessarily unique in your table
      • e.g. Same user posting multiple times to a forum
      • would have user id as primary, and then timestamp as the sort key
      • Primary key could be a composite key consisting of:
        • Partition key: user ID
        • Sort key: timestamp of post
        • 2 items have the same partition key, but they must have a different sort key
        • all items with the same partition key are stored together, then sorted according to the sort key value
        • alows you to store multiple items with the same partition key

DynamoDB Access Control

  • Authentication and Access Control is managed using AWS IAM
  • You can create an IAM user within your AWS account which has specific permissions to access and create DynamoDB tables
  • You can create an IAM role which enables you to obtain temporary access keys which can be used to access DynamoDB
  • You can also use a special IAM Condition to restrict user access to only their own records
    • Imagine a mobile gaming app with millions of users
    • Users need to access the high scores for each game they are playing
    • Access must be restrictured to ensure they cannot view anyone else's data
    • This can be done by adding a Condition to an IAM Policy to allow access only to items where the Partition Key value matches their User ID

DynamoDB Exam Tips

  • Amazon DynamoDB is a low latency NoSQL database
  • Consists of, Tables, Items, and Attributes
    • items = rows
    • attributes = columns
  • Supports both document and key-value data models
  • Supported document formats are JSON, HTML, XML
  • 2 types of Primary Key
    • Partition key
    • Composite key (primary key + sort key)
  • 2 consistency models
    • Strongly Consistent
      • any writes that occurred before the read will be reflected in the read
    • Eventually Consistent
      • Performance can be better, but can take up to 1 second for new writes to be reflected in your read
  • Access is controlled using IAM policies
  • Fine grained access control using IAM condition parameter
    • dynamodb:LeadingKeys to allow users to access only the items where the partition key value matches their user ID