GetItem in DynamoDB Using Java (Guide w/ Code Examples)

Provided by Rafal Wilinski
You can use the getTable method followed by a getItem method to fetch an item belonging to a particular table via a given partition key.
The following code will retrieve an item with a primary key (id) value of 123from the table my-table and prints the value of the name attribute.
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Item; import com.amazonaws.services.dynamodbv2.document.PrimaryKey; import com.amazonaws.services.dynamodbv2.document.Table; public class GetItemExample { public static void main(String[] args) { AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build(); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "my-table"; Table table = dynamoDB.getTable(tableName); String primaryKeyName = "id"; int primaryKeyValue = 123; PrimaryKey primaryKey = new PrimaryKey(primaryKeyName, primaryKeyValue); Item item = table.getItem(primaryKey); // Use the item as neededString attributeName = "name"; String name = item.getString(attributeName); System.out.println("Retrieved item: " + name); } }
Similar Code Examples
- Batch Write Using DynamoDB Mapper
- Update Multiple Attributes in DynamoDB Using Java
- Get Multiple Items in DynamoDB Using Java
- Query Date Range in DynamoDB Using Java
- Update Expression in DynamoDB Using Java
- Batch Read in DynamoDB Using Java
- Delete in DynamoDB Using Java
- Delete by Hashkey Using DynamoDB Mapper
- Conditional Update in DynamoDB Using Java
- Get All Items from DynamoDB Using Java
- Batch Write Item in DynamoDB Using Java
- Query Hash Key Only in DynamoDB Using Java
- Delete Multiple Items in DynamoDB Using Java
- Insert in DynamoDB Using Java
- Update Attribute in DynamoDB Using Java
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
- New in Dynobase 3.0
- Semantic and Vector Search
- Schema Explorer
- Visual JSON Path Filtering
- Visual Item Diff
- MCP Server for AI Tools
- Use SQL with DynamoDB
- Import CSV To DynamoDB
- Import JSON To DynamoDB
- Export DynamoDB To JSON
- Export DynamoDB To S3
- Export DynamoDB To CSV
- DynamoDB Update Item
- DynamoDB Delete All Items
- DynamoDB Delete Item
- DynamoDB Create Table
- DynamoDB Delete Table
- DynamoDB Conditional Update
DynamoDB Tools
DynamoDB Info
© 2026 Dynobase