Dynamodb Conecpts

(this post if part of the material I cover in my devops course)

Core DynamoDB Objects

  • Tables
    DynamoDB stores data in tables. A table is a collection of data.
    DynamoDB table
  • Items
    Each table contains zero or more items. An item is a group of attributes that is uniquely identifiable among all of the other items.
    DynamoDB table Items
  • Attributes
    Each item is composed of one or more attributes. An attribute is a fundamental data element, something that does not need to be broken down any further.
    DynamoDB table Items

Example: People Table

  • Here's an example for a dynamodb table:
 1{
 2    "PersonID": 101,
 3    "LastName": "Smith",
 4    "FirstName": "Fred",
 5    "Phone": "555-4321"
 6}
 7
 8{
 9    "PersonID": 102,
10    "LastName": "Jones",
11    "FirstName": "Mary",
12    "Address": {
13                "Street": "123 Main",
14                "City": "Anytown",
15                "State": "OH",
16                "ZIPCode": 12345
17    }
18}
19
20{
21    "PersonID": 103,
22    "LastName": "Stephens",
23    "FirstName": "Howard",
24    "Address": {
25                "Street": "123 Main",
26                "City": "London",                                    
27                "PostalCode": "ER3 5K8"
28    },
29    "FavoriteColor": "Blue"
30}
  • This is a single table with three items.
  • Note that the items do not have a fixed structure, so the table is schemaless.
  • Most of the attributes are scalar, which means that they can have only one value. Strings and numbers are common examples of scalars.
  • Some of the items have a nested attribute (like Address). DynamoDB supports nested attributes up to 32 levels deep.

Keys

  • Each item in the table has a unique identifier, or primary key, that distinguishes the item from all of the others in the table.
  • In the People table (previous example), the primary key consists of one attribute (PersonID).
  • Sometimes, the primary key can be made of two keys.
    Here's an example:
 1{
 2    "Artist": "No One You Know",
 3    "SongTitle": "My Dog Spot",
 4    "AlbumTitle": "Hey Now",
 5    "Price": 1.98,
 6    "Genre": "Country",
 7    "CriticRating": 8.4
 8}
 9
10{
11    "Artist": "No One You Know",
12    "SongTitle": "Somewhere Down The Road",
13    "AlbumTitle": "Somewhat Famous",
14    "Genre": "Country",
15    "CriticRating": 8.4,
16    "Year": 1984
17}
18
19{
20    "Artist": "The Acme Band",
21    "SongTitle": "Still in Love",
22    "AlbumTitle": "The Buck Starts Here",
23    "Price": 2.47,
24    "Genre": "Rock",
25    "PromotionInfo": {
26        "RadioStationsPlaying": [
27            "KHCR",
28            "KQBX",
29            "WTNR",
30            "WJJH"
31        ],
32        "TourDates": {
33            "Seattle": "20150622",
34            "Cleveland": "20150630"
35        },
36        "Rotation": "Heavy"
37    }
38}
39
40{
41    "Artist": "The Acme Band",
42    "SongTitle": "Look Out, World",
43    "AlbumTitle": "The Buck Starts Here",
44    "Price": 0.99,
45    "Genre": "Rock"
46} 
  • The primary key for Music consists of two attributes (Artist and SongTitle).
  • Each item in the table must have these two attributes. The combination of Artist and SongTitle distinguishes each item in the table from all of the others.
  • When a table has a primary key made of one attribute, this attribute is the partition key.
  • When a table has a primary key made of two keys, one is the partition key, and the other is the sort key
  • In our example Artist was the partition key.

The meaning of partition, and partition key