Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 37 ยท Data Model and Keys

Attribute Data Types

Learn every DynamoDB data type: string, number, binary, boolean, null, list, map and the three set types, plus the type rules for key attributes.

Every attribute value in DynamoDB has a type, and the type decides what you can compare, sort, index and update. There are ten types in three families: scalar, document and set. The list is short, which makes it easy to learn, but the details (numbers as strings, sets that cannot be empty, key types that are restricted) cause real bugs. This lesson covers all of them.

Scalar types

A scalar holds exactly one value.

Tag Type Notes
S String UTF-8, at least one character for a key, compared by UTF-8 byte order
N Number Up to 38 digits of precision, positive, negative or zero
B Binary Raw bytes, sent base64-encoded in the API
BOOL Boolean true or false
NULL Null A present attribute with no value

Numbers deserve attention. DynamoDB stores them as decimal numbers with up to 38 significant digits, so it does not lose precision the way a 64-bit float does. On the wire a number travels as a string ({"N": "19.99"}), which is why SDKs for some languages hand you a decimal type or a string rather than a float. There is no separate integer type and no built-in date type.

Document types

Tag Type Notes
L List Ordered, elements may have mixed types
M Map Unordered name/value pairs, values can be any type

Lists and maps nest up to 32 levels, and you can read or update a single nested element with a path such as Address.City or Lines[0].Qty, using the expressions covered in UpdateItem. A map is the usual way to store a small structured value inside an item.

Set types

Tag Type Notes
SS String set Unique strings
NS Number set Unique numbers
BS Binary set Unique binary values

A set is an unordered collection of unique values of one type. DynamoDB rejects duplicates inside a set value, and it rejects empty sets: if the set would become empty, you remove the attribute instead. Sets support the special update actions ADD and DELETE for adding and removing members atomically, without reading the item first. Choose a set for membership-style data such as tags or permissions. Choose a list when order or duplicates matter.

Key attribute types

Only three types may be used for a key attribute (partition key, sort key, or an index key): string, number or binary. You cannot key on a boolean, a list, a map or a set. This matters when you choose how to store a date or a timestamp, because there is no date type.

Store dates as one of:

  • an ISO 8601 string such as 2026-03-14T09:30:00Z, which sorts correctly as text, or
  • a number of epoch seconds or milliseconds, which also sorts correctly and is required for TTL.

Whichever you pick, use it consistently. A string sorts as "10" < "9", so never store numbers as strings when you want numeric ordering.

Python Stand-in: string order vs number order

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A type encoder and decoder

The next stand-in converts plain Python values to DynamoDB's typed JSON and back, including the three set types. It also enforces two real rules: sets cannot be empty, and set members must share a type.

Python Stand-in: typed JSON round trip with sets

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Choosing a type

  • Identifiers: string. Use UUIDs, ULIDs or readable prefixed keys.
  • Money: either a decimal number or an integer in minor units (cents), which avoids rounding.
  • Timestamps: ISO 8601 string, or epoch number if the item uses TTL.
  • Flags: BOOL. Do not use strings like "true".
  • Small structured values: map.
  • Tags and permissions: string set.
  • Ordered history of a bounded size: list. For unbounded history, use separate items.

Common mistakes

  • Using a float for money in application code and trusting it to round correctly.
  • Writing an empty string where an empty set or null is meant. Empty strings are now allowed for non-key attributes, but an empty key string is not.
  • Expecting set order to be preserved. It is not.
  • Putting a date in a map and then trying to sort on it. Only a top-level key attribute can be sorted by a query.
  • Mixing types for one attribute across items, such as Age as a number in one and a string in another, which breaks filters and indexes.

If an attribute becomes the key of an index, the type you declare for it must match every item that has it. An item with the wrong type for an indexed attribute is rejected on write, not silently skipped.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which types may be used for a partition key or sort key?

    Key attributes (including index keys) are limited to string, number and binary.
  2. 2. What is true of a DynamoDB set?

    Sets are unordered, unique and homogeneous, and an empty set is not allowed.
  3. 3. Why does 10 sort before 9 when both are stored as strings?

    Strings sort by byte order, so "10" is less than "9". Use the number type when you need numeric ordering.
  4. 4. How are numbers transmitted in the API?

    Numbers travel as strings, such as {"N": "19.99"}, so that up to 38 digits of precision are preserved.
  5. 5. How should you store a timestamp you want to sort on?

    There is no date type. ISO 8601 strings and epoch numbers both sort correctly.

Summary

  • There are ten types: S, N, B, BOOL, NULL, L, M, SS, NS and BS.
  • Numbers keep up to 38 digits and travel as strings; there is no date type.
  • Sets are unique, unordered, single-typed and never empty; lists and maps nest up to 32 levels.
  • Keys can only be strings, numbers or binary.
  • Pick types with sorting and update needs in mind, and keep each attribute's type consistent.

Next: Primary Keys: Partition and Sort