You are currently viewing DynamoDB API – Part One

DynamoDB API – Part One

DynamoDB API – Part One

Hello Everyone

Welcome to CloudAffaire and this is Debjeet

In the last blog post, we have installed DynamoDB in our local system.

https://cloudaffaire.com/install-dynamodb-in-local-system/

In this blog post, we are going to discuss basic API calls to DynamicDB.

DynamoDB API :

AWS provides sets of API to interact with DynamoDB. In this demo, we will go through different sets of API that can be used with DynamoDB. For length constraint, we will divide this blog into two blogs.

CreateTable:

The CreateTable operation adds a new table to your account. In an AWS account, table names must be unique within each region. That is, you can have two tables with the same name if you create the tables in different regions.

Syntax:

Example: We will create a table Employee with a single primary key on id (number field)

DynamoDB API

DescribeTable:

Returns information about the table, including the current status of the table, when it was created, the primary key schema, and any indexes on the table.

Syntax:

Example: We will describe the Employee table that we just created.

DynamoDB API

ListTables:

Returns an array of table names associated with the current account and endpoint. The output from ListTables is paginated, with each page returning a maximum of 100 table names.

Syntax:

Example: List all tables present in DynamoDB.

DynamoDB API

PutItem:

Creates a new item, or replaces an old item with a new item. If an item that has the same primary key as the new item already exists in the specified table, the new item completely replaces the existing item. You can perform a conditional put operation (add a new item if one with the specified primary key doesn’t exist), or replace an existing item if it has certain attribute values. You can return the item’s attribute values in the same operation, using the ReturnValues parameter.

Syntax:

Example: We will insert a single record id = 100 in our Employee table from a JSON file (empl1.json)

Empl1.json:

DynamoDB API

BatchWriteItem:

The BatchWriteItem operation puts or deletes multiple items in one or more tables. A single call to BatchWriteItem can write up to 16 MB of data, which can comprise as many as 25 put or delete requests. Individual items to be written can be as large as 400 KB.

Syntax:

Example: We will insert 2 items (id = 101 and id = 104) in our existing employee table from Jason file (empl2.josn)

empl2.json:

DynamoDB API

Scan:

The Scan operation returns one or more items and item attributes by accessing every item in a table or a secondary index. To have DynamoDB return fewer items, you can provide a FilterExpression operation.

Syntax:

Example: We will get all the id from the Employee table.

DynamoDB API

Hope you have enjoyed this article. In the next blog post, we will continue from here.

To get more details on DynamoDB, please refer below AWS documentation

https://docs.aws.amazon.com/dynamodb/index.html

 

Leave a Reply