Getting an item from the DynamoDB table using the AWS SDK for Java
Let's understand how to get an item from the DynamoDB table using the AWS SDK for Java.
Getting ready
To perform this operation, you can use the IDE of your choice.
How to do it…
Let's try to understand how to retrieve a stored item from the DynamoDB table using Java:
Create an instance of the
DynamoDBclass and initialize it with credentials:AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); client.setRegion(Region.getRegion(Regions.US_EAST_1)); DynamoDB dynamoDB = new DynamoDB(client);
Get the
tableby specifying the name:Table table = dynamoDB.getTable("productTable");Invoke the
GetItemrequest by specifying theprimarykey of the item:Item product = table.getItem(new PrimaryKey("id", 10, "type", "phone"));Here, we have a table with the composite hash and range keys, so we have to provide values for both keys.
How it works…
The API invocations call the DynamoDB services and get the item from...