Skip to content

xarques/cloudcorner-aws-dynamodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Cisco cloud corner on AWS DynamoDB

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:

DynamoDB Consistency Model

  • 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

Prerequisites:

NoSQL Fundamentals

Creating your first DynamoDB Table with the AWS Console

DynamoDB supports two different kinds of primary keys:

  • Partition Key
  • Partition Key and Sort Key
  1. From the AWS console, go to Database -> DynamoDB
  2. Select Create Table
  • Table name: CloudCorner
  • Primary key: UserID Number
  • Click Create

Wait until the CloudCorner table has been created

  1. Select the CloudCorner table
  2. Go to folder Items and select Create Item
  3. Enter:
    • UserId: 1
  4. Click on + -> Append -> String. Enter:
    • LastName: Enter your last name
  5. Click Save

Congratulations: You have inserted your first item in a DynamoDB table

  1. Select Create Item
  2. Enter:
    • UserId: 2
  3. Click on + -> Append -> String. Enter:
    • FirstName: Enter the first name of your colleague
  4. Click Save

You have now created a second item with a different field name

  1. Select item 1 and select Actions -> Edit
  2. Click on + -> Append -> String. Enter:
    • FirstName: Enter your first name
  3. Click Save
  4. Select item 2 and select Actions -> Edit
  5. Click on + -> Append -> String. Enter:
    • LastName: Enter the last name of your colleague
  6. Click Save

You have now added the missing fields into the previous records

Creating a DynamoDB Table with CloudFormation

  1. From the AWS console, go to Management Tools -> CloudFormation
  2. Select Create New Stack
  3. Click on Choose file into the Choose a template section and select the weatherstationtable.json file in the resource directory of this repository
  4. Click Next
  5. Enter weatherstation in the Stack Name and Click Next
  6. Click Next
  7. Click Create
  8. From the AWS console, go to Database -> DynamoDB Wait until the weatherstation_data table has been created1.
  9. Select the weatherstation_data table and check that it contains fields station_id and dateandtime

Use the DynamoDB CLI to interact with your tables

  1. Open a console
  2. Try the different commands available in the ./resources/COMMANDS_USED.TXT available in this repository

Controlling Table performance

  • 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

Conditional and Update expressions

Update expressions

Perform server side database manipulations Update expressions consists of 4 operations:

  • REMOVE
  • SET
  • ADD
  • DELETE

Conditional expressions

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

Introduction to Partitions

  • 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

Advanced Key Design

  • 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

Releases

No releases published

Packages