dynobase-icon
Dynobase

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

You can use the PutItemRequest class offered by the DynamoDB SDK to put new items into DynamoDB.

The following code inserts an item into the table my-table with three attributes: a primary key attribute ("id") and two other attributes ("attribute1" and "attribute2"). The values for these attributes are specified in the AttributeValue objects

import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.AttributeValue.*; import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; import java.util.HashMap; import java.util.Map; public class InsertItem { public static void main(String[] args) { DynamoDbClient ddb = DynamoDbClient.create(); String tableName = "my-table"; Map<String, AttributeValue> item = new HashMap<>(); item.put("id", AttributeValue.builder().s("12345").build()); item.put("attribute1", AttributeValue.builder().s("value1").build()); item.put("attribute2", AttributeValue.builder().s("value2").build()); PutItemRequest request = PutItemRequest.builder() .tableName(tableName) .item(item) .build(); ddb.putItem(request); } }

Better DynamoDB experience.

First 7 days are on us. No strings attached.

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2023 Dynobase
+
Tired of AWS Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.