Simple Primary Key: This is composed of one attribute called the Partition Key. The primary key is used to uniquely identify each item in an Amazon DynamoDB table. Uniquely Identifying Items in a Table with Primary Key In our example, each order item has OrderValue, OrderDate as scalar attributes and products list as a nested type attribute. Most of the attributes are scalar like strings and numbers while some are of nested types like lists, maps, or sets. They are similar to columns in a relational database.Įach item has its own attributes. An item is composed of attributes, which are different elements of data for a particular item. Each order is uniquely identified by a combination of customerID and orderID.Ī table contains one or more items. This diagram shows the organization of order records placed by a customer in a Order table. Other than the primary key, we do not need to define any additional attributes when creating a table. Like in many databases, a table is the fundamental concept in DynamoDB where we store our data. Here we will only skim through the main concepts that are essential for designing our applications. There is plenty to know about DynamoDB for building a good understanding for which we should refer to the official documentation. Both the keys and the values can be simple or complex objects. A key-value database stores data as a collection of key-value pairs.
This article is accompanied by a working code example on GitHub.Īmazon DynamoDB is a key-value database.
If you want to go deeper and learn how to deploy a Spring Boot application to the AWS cloud and how to connect it to cloud services like RDS, Cognito, and SQS, make sure to check out the book Stratospheric - From Zero to Production with Spring Boot and AWS! Example Code For example, in this example, I named my file scrantonTable.js.This article gives only a first impression of what you can do with AWS.
Create a javascript file with the following code snippet. I hope you get the drift and I will stop with my theoretical babblings. Items can share partition keys, but not sort keys.
Partition Key and Sort Key − This key, known as the “Composite Primary Key”, consists of two attributes.ĭynamoDB applies the first attribute to a hash function, and stores items with the same partition key together with their order determined by the sort key. Partition Key − This simple primary key consists of a single attribute referred to as the “partition key.” Internally, DynamoDB uses the key value as input for a hash function to determine storage. The Table Creation requires not only setting a name, but also the primary key, which identifies table items. Run aws dynamodb list-tables -endpoint-url and you'll be greeted with an object which has a key named TableNames on your console. Now we can create a table on our very own locally brewed DynamoDB instance.īefore we create a table, let's see if everything working properly. Enter fullscreen mode Exit fullscreen mode Let's get to workĪwesome!.