Search in sources :

Example 1 with PutItemEnhancedRequest

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();
    }
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region) PutItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Aggregations

DynamoDbEnhancedClient (software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)1 PutItemEnhancedRequest (software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest)1 Region (software.amazon.awssdk.regions.Region)1 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)1