Perform operations - AWS SDK for Java 2.x

Perform operations

After the table is created, use the DynamoDbTable instance to perform operations against the DynamoDB table.

In the following example, a singleton DynamoDbTable<Customer> is passed as a parameter along with a Customer data class instance to add a new item to the table.

public static void putItemExample(DynamoDbTable<Customer> customerTable, Customer customer){ logger.info(customer.toString()); customerTable.putItem(customer); }
Customer customer = new Customer(); customer.setId("1"); customer.setCustName("Customer Name"); customer.setEmail("customer@example.com"); customer.setRegistrationDate(Instant.parse("2023-07-03T10:15:30.00Z"));

Before sending the customer object to the DynamoDB service, log the output of the object's toString() method to compare it to what the enhanced client sends.

Customer [id=1, name=Customer Name, email=customer@example.com, regDate=2023-07-03T10:15:30Z]

Wire-level logging shows the payload of the generated request. The enhanced client generated the low-level representation from the data class. The regDate attribute, which is an Instant type in Java, is represented as a DynamoDB string.

{ "TableName": "Customer", "Item": { "registrationDate": { "S": "2023-07-03T10:15:30Z" }, "id": { "S": "1" }, "custName": { "S": "Customer Name" }, "email": { "S": "customer@example.com" } } }