0
0
DynamoDBquery~5 mins

PutItem (creating items) in DynamoDB

Choose your learning style9 modes available
Introduction

PutItem lets you add a new item or replace an existing one in a DynamoDB table. It helps you save data quickly and easily.

When you want to add a new user profile to your app database.
When you need to save a new order in an online store.
When updating a device's settings by replacing the old data.
When logging an event or action with fresh details.
When creating a new record for inventory in a warehouse system.
Syntax
DynamoDB
PutItem {
  TableName: "TableName",
  Item: {
    "PrimaryKey": {"S": "value"},
    "Attribute1": {"S": "value"},
    "Attribute2": {"N": "123"}
  }
}

The TableName is the name of your DynamoDB table.

The Item is a map of attribute names to their values and types.

Examples
Adds a new user with ID, name, and age.
DynamoDB
PutItem {
  TableName: "Users",
  Item: {
    "UserID": {"S": "user123"},
    "Name": {"S": "Alice"},
    "Age": {"N": "30"}
  }
}
Creates a new order with ID, amount, and status.
DynamoDB
PutItem {
  TableName: "Orders",
  Item: {
    "OrderID": {"S": "order789"},
    "Amount": {"N": "250"},
    "Status": {"S": "Pending"}
  }
}
Sample Program

This adds a new book record with ISBN, title, author, and year to the Books table.

DynamoDB
PutItem {
  TableName: "Books",
  Item: {
    "ISBN": {"S": "978-1234567890"},
    "Title": {"S": "Learn DynamoDB"},
    "Author": {"S": "Jane Doe"},
    "Year": {"N": "2024"}
  }
}
OutputSuccess
Important Notes

If an item with the same primary key exists, PutItem replaces it completely.

You must provide all required attributes for the table's primary key.

PutItem is simple but does not check if the item already exists unless you add conditions.

Summary

PutItem adds or replaces a single item in a DynamoDB table.

You specify the table name and the item attributes with their types.

It is useful for saving new data or updating existing records quickly.