dynobase-icon
Dynobase

DynamoDB Data & Attribute Types - The Complete List

Rafal Wilinski

Written by Rafal Wilinski

Published on February 26th, 2020

    Still using AWS console to work with DynamoDB? 🙈

    Time to 10x your DynamoDB productivity with Dynobase [learn more]

    DynamoDB currently supports the following list of data types:

    Number [N]

    Numbers in DynamoDB can be positive, negative, or zero. Keep in mind that trailing and leading zeros are removed. Numbers can also be used to represent dates using the Epoch format. This can use less storage and might be easier to parse from your application.

    The Number type can store 128-bit integers or floats with up to 38 digits of decimal precision.

    The largest and smallest Number, respectively, that you can store in DynamoDB are:

    99,999,999,999,999,999,999,999,999,999,999,999,999 (10^38-1) -99,999,999,999,999,999,999,999,999,999,999,999,999 (-10^38+1)

    If you need to store a smaller/bigger number, or a float with greater precision, consider using the String type.

    String [S]

    DynamoDB supports UTF-8 binary encoded strings, which length is limited by the maximum item size which is 400 KB. If a String is used as a primary key, then the length of it is limited to 2048 bytes for a single key and 1024 bytes for a composite key.

    The size of a string is calculated as (length of attribute name) + (number of UTF-8-encoded bytes).

    Binary [B]

    Just like with Strings, binary length is limited by the maximum item size, which is 400 KB. Binaries must be encoded using base64 before being sent to DynamoDB. Binary types can also be used for keys and they have the same length restriction rules as Strings.

    The size of a binary attribute is (length of attribute name) + (number of raw bytes).

    Boolean [BOOL]

    Must be true or false.

    Null

    Represents an unknown, null, or undefined value.

    List

    A List is an equivalent of a JavaScript Array, which can store multiple items of different types.

    Example Array:

    Map

    A Map (also known as an Object) is a JSON-like structure of unordered key-value pairs. Similar to a List, a Map can contain mixed type elements.

    Example Map:

    Keep in mind that DynamoDB automatically orders keys in the Map. If the order of keys is important in your application, consider stringifying your JSON first and saving it as a string.

    Moreover, if your object has a lot of repeating keys and values, you might consider stringifying it and compressing it with gzip. This can make your blobs up to 10 times smaller. The drawback, though, is that you won't be able to natively query on object nested keys.

    StringSet [SS], BinarySet [BS], and NumberSet [NS]

    DynamoDB supports multiple types of Sets where, unlike Lists, all the elements within a set must be of the same type and all the elements must also be unique. Another difference between a Set and a List is that a Set does not preserve the sequence of elements. BinarySet can only contain Binary elements, NumberSet can only contain Numbers, and StringSet can only contain Strings.

    Example:

    Additional Considerations

    When designing your DynamoDB tables, it's important to consider the access patterns of your application. DynamoDB is optimized for high-performance reads and writes, but the way you structure your data can significantly impact performance and cost. For example, using composite keys can help you efficiently query related items, while secondary indexes can provide additional query flexibility.

    DynamoDB also supports transactions, which allow you to perform multiple operations atomically. This can be particularly useful for maintaining data consistency in complex applications. However, transactions can incur additional costs and latency, so they should be used judiciously.

    Finally, DynamoDB integrates well with other AWS services such as Lambda, S3, and Kinesis, enabling you to build scalable, event-driven architectures. For instance, you can trigger a Lambda function to process data changes in a DynamoDB table, or use DynamoDB Streams to capture and process real-time data updates.

    Tired of switching accounts and regions? Use Dynobase.

    Try 7-day free trial. No strings attached.

    Product Features

    Download
    /
    Changelog
    /
    Pricing
    /
    Member Portal
    /
    Privacy
    /
    EULA
    /
    Twitter
    © 2024 Dynobase