DynamoDB — Intro with quick-start examples

bschandramohan
Jun 26, 2019 · 2 min read

DynamoDB is a NO-SQL, key-value and document database. It’s developed and supplied by Amazon AWS — i.e., it’s a fully managed system where Amazon AWS takes care of the provisioning, clustering, scaling, throughput adherence, backup and restore, etc., based on the configurations.

DynamoDB can handle more than 10 trillion requests per day and can support peaks of more than 20 million requests per second.

Read more about the benefits in their homepage

I am not a huge fan of tutorials, but this is one you can refer to: https://aws.amazon.com/getting-started/tutorials/create-nosql-table/

The one I used for my learning was the developer guide:

Core Components

Tables, Items, and Attributes

Primary Key: Partition Key OR Partition Key + Sort Key — Partition Key Design

Secondary Indexes

Streams

API Layer

Control Plane (a.k.a DDL in SQL)

Data Plane (a.k.a DML in SQL)

Stream APIs

Transactions

Data Types

Scalar types, Document types, Set types

Let’s go onto trying out stuff!

We can try DynamoDB in 2 different ways :

  1. Connect to the AWS web service (they have free trials)
  2. Have a local instance in your machine -can be installed in 3 ways —
    a. Download tar and run the jar locally (Link)
    b. Use dynamodb docker image (Link)
    c. Use brew (Link)

We use AWS CLI or AWS SDK to connect to DynamoDB. For this article, let’s use AWS CLI.

brew install awscli
aws
aws help

To configure aws, run below: (reference this link ; For local dynamodb access key id and secret access key can be anything fake)

aws configure

Now you should be able to query local dynamodb from cli using commands like:

aws dynamodb list-tables --endpoint-url http://localhost:8000

Creating a table:

aws dynamodb --endpoint-url http://localhost:8000 create-table \
--table-name Recipe \
--attribute-definitions \
AttributeName=ItemName,AttributeType=S \
AttributeName=Rating,AttributeType=N \
--key-schema AttributeName=ItemName,KeyType=HASH AttributeName=Rating,KeyType=RANGE \
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1

Verifying the table structure:

aws dynamodb --endpoint-url http://localhost:8000 describe-table --table-name "Recipe"

Putting an Item (primary key — (here, partition key + range key) is mandatory)

aws dynamodb --endpoint-url http://localhost:8000 put-item --table-name Recipe --item '{"ItemName": { "S": "Chicken Biriyani"}, "Rating": {"N": "10"}, "SpicyLevel": {"N": "5"}}'

Getting an item: (Pass primary key (here, partition key + range key) to fetch)

aws dynamodb --endpoint-url http://localhost:8000 get-item --table-name Recipe --key '{"ItemName": { "S": "Chicken Biriyani"}, "Rating": {"N": "10"}}'

Querying items:

aws dynamodb query --endpoint-url http://localhost:8000 --table-name Recipe --key-condition-expression "ItemName = :name" --expression-attribute-values '{":name" : { "S": "Chicken Biriyani"}}'

TechieConnect

My technical posts mostly on Java backend services

bschandramohan

Written by

Software Engineer working on Java based Micro-services deployed on AWS cloud. California, US resident currently — born and brought up in Bangalore, India.

TechieConnect

My technical posts mostly on Java backend services

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade