use of software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBEnhanced method injectDynamoItem.
// Uses the Enhanced Client to inject a new post into a DynamoDB table
public void injectDynamoItem(Greeting item) {
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).credentialsProvider(EnvironmentVariableCredentialsProvider.create()).build();
try {
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
// Create a DynamoDbTable object
DynamoDbTable<GreetingItems> mappedTable = enhancedClient.table("Greeting", TableSchema.fromBean(GreetingItems.class));
GreetingItems gi = new GreetingItems();
gi.setName(item.getName());
gi.setMessage(item.getBody());
gi.setTitle(item.getTitle());
gi.setId(item.getId());
PutItemEnhancedRequest enReq = PutItemEnhancedRequest.builder(GreetingItems.class).item(gi).build();
mappedTable.putItem(enReq);
} catch (Exception e) {
e.getStackTrace();
}
}
Aggregations