- AWS Code Sample

/* Copyright, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package example; import; import; import; import; import; import; import; import; import; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneOffset; /* Prior to running this code example, create a table named Case with a PK named id */ public class PersistCase { // Puts an item into a DynamoDB table public void putRecord(String caseId, String employeeName, String email) { // Create a DynamoDbClient object Region region = Region.US_WEST_2; DynamoDbClient ddb = DynamoDbClient.builder() .region(region) .build(); // Create a DynamoDbEnhancedClient and use the DynamoDbClient object DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder() .dynamoDbClient(ddb) .build(); try { // Create a DynamoDbTable object DynamoDbTable<Case> caseTable = enhancedClient.table("Case", TableSchema.fromBean(Case.class)); // Create an Instat object LocalDate localDate = LocalDate.parse("2020-04-07"); LocalDateTime localDateTime = localDate.atStartOfDay(); Instant instant = localDateTime.toInstant(ZoneOffset.UTC); // Populate the table Case caseRecord = new Case(); caseRecord.setName(employeeName); caseRecord.setId(caseId); caseRecord.setEmail(email); caseRecord.setRegistrationDate(instant) ; // Put the case data into a DynamoDB table caseTable.putItem(caseRecord); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("done"); } // Create the Case table to track open cases created in the workflow @DynamoDbBean public static class Case { private String id; private String name; private String email; private Instant regDate; @DynamoDbPartitionKey public String getId() { return; }; public void setId(String id) { = id; } @DynamoDbSortKey public String getName() { return; } public void setName(String name) { = name; } public String getEmail() { return; } public void setEmail(String email) { = email; } public Instant getRegistrationDate() { return regDate; } public void setRegistrationDate(Instant registrationDate) { this.regDate = registrationDate; } } }