AWS DynamoDB with Python (Boto3)— Part 1 — Intro to DynamoDB & local Installation

Brief about Amazon DynamoDB

According to official documentation,

Amazon DynamoDB is a fully managed, serverless, key-value NoSQL database designed to run high-performance applications at any scale

Core Components

In DynamoDB, tables, items, and attributes are the core components

table — Similar to a TABLE in RDBMS

item — Similar to ROW in RDBMS TABLE. No limit on number of items per table

attribute — Similar to COLUMN IN RDBMS TABLE . Attribute is something that does not need to be broken down any further. Each item contains one or more attributes. DynamoDB attribute can of type — String, Number, Binary List, a Map, or a Set

Each item in the table should have a unique key (Primary Key). Rest of the attributes are schema-less. Its mandatory to specify schema for the primary key at the time of table creation itself.

Types of Primary Key

  • Partition Key (hash attribute)
  • Partition Key & Sort Key (range attribute)

If we configure only Partition key as Primary Key, we can uniquely access the item in DynamoDB using Partition key

If we configure both Partition & Sort Key as Primary Key, we need to specify both of them, to uniquely access the item

Key can be of type — string, number, or binary

I feel this much of introduction is enough to start with DynamoDB.

Installing DynamoDB in local

DynamoDB can be installed in local in two ways

By downloading JAR & run java -jar command (or) By downloading DynamoDB docker image. Personally I prefer using docker image

Steps

Download & Install Docker Desktop

Run the following commands

  1. Create Docker Network
> docker network create dynamo-local-network

2. Download & Start DynamoDB as Docker Container in Local

> docker run -d -p 8000:8000 --network=dynamo-local-network --name dynamo-local amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb

If we use -inMemory instead of -sharedDb, data will be stored only in memory & once we terminate the docker container, the data will be lost

The above command is only for starting DynamoDB Docker Container for the first time. Afterwards, we can simply use following command

> docker start dynamo-local

To test DynamoDB local connection

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

DynamoDB Workbench

Just like how we use MySQL Workbench to access MySQL database in GUI, AWS offers a workbench for DynamoDB called NoSQL Workbench

Install it from here — https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/workbench.settingup.html

After installation, open NoSQL Workbench → Operation Builder from Left Side Menu -> Click Add Connection Button -> In the Add a new database connection popup, choose DynamoDB Local tab -> Hit Connect

Thats all about DynamoDB & its installation !

Next article in this seriesAWS DynamoDB with Python (Boto3) — Part 2 — Create Table & Insert Item

 by the author.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store