Amazon DynamoDB is a fully managed NoSQL database service provided by AWS
This workshop has been inspired by the aCloudGuru course Amazon DynamoDB - From Beginner to Pro
The GIT repository of Amazon DynamoDB - From Beginner to Pro course is available for free: https://github.com/acantril/aCloudGuru-DynamoDB
See also:
- SSD Storage
- Consistent, reliable low latency reads and writes
- Every data block is stored three times
- Support Eventual consistency (default) or Strong consistency for read operations
- You must have a valid AWS account
- You must have downloaded and configured the AWS CLI
- Schema-less
- No relationships (except for Graph DB)
- No Structured Query Language (SQL)
- ACID (Atomicity, Consistency, Isolation, Durability) vs BASE (Basically Available, Soft state, Eventual consistency)
- Horizontal Scalability
- Different categories of NoSQL databases:
- key/value
- Document DB (CouchDB, MongoDB)
- Column Family (For analytics)
- Graph Style DB (Importance of Relationships)
DynamoDB supports two different kinds of primary keys:
- Partition Key
- Partition Key and Sort Key
- From the AWS console, go to Database -> DynamoDB
- Select Create Table
- Table name: CloudCorner
- Primary key: UserID Number
- Click Create
Wait until the CloudCorner table has been created
- Select the CloudCorner table
- Go to folder Items and select Create Item
- Enter:
- UserId: 1
- Click on + -> Append -> String. Enter:
- LastName: Enter your last name
- Click Save
Congratulations: You have inserted your first item in a DynamoDB table
- Select Create Item
- Enter:
- UserId: 2
- Click on + -> Append -> String. Enter:
- FirstName: Enter the first name of your colleague
- Click Save
You have now created a second item with a different field name
- Select item 1 and select Actions -> Edit
- Click on + -> Append -> String. Enter:
- FirstName: Enter your first name
- Click Save
- Select item 2 and select Actions -> Edit
- Click on + -> Append -> String. Enter:
- LastName: Enter the last name of your colleague
- Click Save
You have now added the missing fields into the previous records
- From the AWS console, go to Management Tools -> CloudFormation
- Select Create New Stack
- Click on Choose file into the Choose a template section and select the weatherstationtable.json file in the resource directory of this repository
- Click Next
- Enter weatherstation in the Stack Name and Click Next
- Click Next
- Click Create
- From the AWS console, go to Database -> DynamoDB Wait until the weatherstation_data table has been created1.
- Select the weatherstation_data table and check that it contains fields station_id and dateandtime
- Open a console
- Try the different commands available in the ./resources/COMMANDS_USED.TXT available in this repository
- Read Capacity Units (RCU): up to 4KB data
- Write Capacity Units (WCU) : up to 1KB data
- Both are allocated on a PER SECOND basis
- Operations are always rounded to a multiple of 1KB or 4KB minimum
- 3KB Read per second = 3KB / 4KB = 0.75 = 1 RCU
- 1.5KB Write per second = 1.5KB / 1KB = 1.5 = 2 WCU
- Eventually consistent read use HALF of the above RCU
Capacities can be modified through :
- The Capacity tab
- The CLI - Update-table
aws dynamodb update-table --table-name weatherstation_data --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
- SDK API - Update-Table
Perform server side database manipulations Update expressions consists of 4 operations:
- REMOVE
- SET
- ADD
- DELETE
Available on write operations (PUT, UPDATE and DELETE) Perform an action depending on a condition:
- Attribute Exists or Not_Exists
- Attribute has a specific Type
- Attribute begins_with, contains or has size X Use traditional comparators: =, <>, <, >, <=, >= And keywords BETWEEN or IN Can be combined with Update Expressions
- Underlying storage and processing nodes of dynamodb
- Initially One table equals One partition
- You can't directly see the number of partitions
- You don't directly control the number of partitions
- A partition can store 10 GB of data
- Partition keys need to be unique and non null
- Partition keys should have many unique values
- Don't use the sort key to fake this !!
- Uniform read and write across all partition key values
- Uniform temporal read and write pattern
- If you don't have a suitable key - make one
- Aim not to mix HOT and COLD data