0
0
DynamoDBquery~5 mins

GetItem (reading single item) in DynamoDB

Choose your learning style9 modes available
Introduction

GetItem lets you quickly find one specific item in a DynamoDB table using its unique key.

When you want to look up a user's profile by their user ID.
When you need to get details of a single order using the order number.
When you want to check the status of a specific product by its product ID.
When you want to retrieve a single record without scanning the whole table.
Syntax
DynamoDB
GetItem {
  TableName: "TableName",
  Key: {
    "PrimaryKeyName": { "S": "PrimaryKeyValue" }
  }
}

The Key must include the primary key attributes exactly as defined in your table.

Use S for string type, N for number type, and B for binary type values.

Examples
Get the user with ID 'user123' from the 'Users' table.
DynamoDB
GetItem {
  TableName: "Users",
  Key: {
    "UserID": { "S": "user123" }
  }
}
Get the order with numeric ID 101 from the 'Orders' table.
DynamoDB
GetItem {
  TableName: "Orders",
  Key: {
    "OrderID": { "N": "101" }
  }
}
Sample Program

This query fetches the product with ID 'P1001' from the 'Products' table.

DynamoDB
GetItem {
  TableName: "Products",
  Key: {
    "ProductID": { "S": "P1001" }
  }
}
OutputSuccess
Important Notes

If the item does not exist, the response will not include an Item field.

GetItem is fast because it uses the primary key directly, no scanning needed.

Summary

GetItem fetches one item by its primary key from a DynamoDB table.

It is efficient and quick for retrieving single records.

Always provide the exact key attributes in the request.