0
0
DynamoDBquery~5 mins

Key-value and document store model in DynamoDB

Choose your learning style9 modes available
Introduction

This model helps you store and find data quickly using keys. It is easy to save whole documents like JSON without strict tables.

When you want to save user profiles with different details for each user.
When you need to quickly find a product by its unique ID in an online store.
When storing session data for a website where each session has different information.
When you want to keep flexible data that changes often without redesigning tables.
Syntax
DynamoDB
PutItem
{
  "TableName": "TableName",
  "Item": {
    "PrimaryKey": { "S": "key_value" },
    "Attribute1": { "S": "value1" },
    "Attribute2": { "N": "123" }
  }
}

GetItem
{
  "TableName": "TableName",
  "Key": {
    "PrimaryKey": { "S": "key_value" }
  }
}
Use PutItem to add or replace an item with a unique key.
Use GetItem to retrieve an item by its key quickly.
Examples
This saves a user with ID 'user123' and their name and age.
DynamoDB
PutItem
{
  "TableName": "Users",
  "Item": {
    "UserID": { "S": "user123" },
    "Name": { "S": "Alice" },
    "Age": { "N": "30" }
  }
}
This fetches the user with ID 'user123'.
DynamoDB
GetItem
{
  "TableName": "Users",
  "Key": {
    "UserID": { "S": "user123" }
  }
}
This stores a product with nested details as a document.
DynamoDB
PutItem
{
  "TableName": "Products",
  "Item": {
    "ProductID": { "S": "p001" },
    "Details": { "M": {
      "Name": { "S": "Laptop" },
      "Price": { "N": "999" },
      "Specs": { "M": {
        "RAM": { "S": "16GB" },
        "Storage": { "S": "512GB" }
      }}
    }}
  }
}
Sample Program

This example saves a book with its ISBN as key and then retrieves it.

DynamoDB
PutItem
{
  "TableName": "Books",
  "Item": {
    "ISBN": { "S": "978-1234567890" },
    "Title": { "S": "Learn DynamoDB" },
    "Author": { "S": "Jane Doe" },
    "Details": { "M": {
      "Pages": { "N": "250" },
      "Publisher": { "S": "Tech Books" }
    }}
  }
}

GetItem
{
  "TableName": "Books",
  "Key": {
    "ISBN": { "S": "978-1234567890" }
  }
}
OutputSuccess
Important Notes

Keys must be unique in the table to avoid overwriting data.

Document attributes can store nested data like JSON objects.

This model is great for flexible and fast lookups but not for complex joins.

Summary

Key-value and document store model uses unique keys to save and find data fast.

It allows storing flexible documents like JSON with nested details.

Ideal for simple, fast access to data without complex relationships.