Data Types

Understand the various data types used by the attributes.

We can categorize the data types used by attributes as:

  1. Scalar
  2. Document
  3. Set

Scalar

The types contained in this category are String, Number, Boolean, Null, and Binary. These data types contain a single value. Let’s look at each one of them.

String

We can store a string of any size, constrained only by the DynamoDB item size limit. That is, we can store a string of any size as long as your item is less than 400 KB in size. However, if the given string type attribute is used as the primary key, it should be less than 2048 bytes for a single key and 1024 bytes for a composite key.

Examples: “Manager”, “Artist”, and “Read-only”

Number

We can store all numbers with this data type. We can map the basic number types, namely int, double, and float of your programming language to Number in DynamoDB. These numbers can be positive, negative, zero, integer, or decimal.

Examples: 124, 42.34, -5634, and so on.

Boolean

The value of this attribute can either be true or false.

Null

This is used to represent the null value, i.e. values that are unknown or undefined.

Binary

This attribute type is mostly used to store images, documents, or encrypted messages. Binary can also be used as the primary key. The size restrictions are exactly the same as string data type, i.e.,

  • Total item size should be less than 400 KB
  • When used as a primary key, it should be less than 2048 bytes and 1024 bytes for single and composite keys respectively.

Document

These are collection data types. There are two types of collections supported by DynamoDB, namely: List and Map.

Map

A map is a collection of key-value pairs. We can think of it as similar to a JSON object. These key-value pairs are not ordered.

List

A list is a collection of values. The values can be of the same type or different types. We can think of this collection as similar to Python lists. The elements in this data type are ordered. We can get the elements by their index.

Set

Sets in DynamoDB are the same as lists but with some added restrictions. All of the elements in the set should be of the same type and should be unique. Unlike List, the elements are not ordered. There are three types of Sets in DynamoDB depending on the data types of list elements:

  1. NumberSet: Elements are Numbers
  2. StringSet: Elements are Strings
  3. BinarySet: Elements are Binary objects

Sets have a size restriction, according to which the size of the item should not exceed 400KB.