use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class ScanEmployees method sendEmployeMessage.
public Boolean sendEmployeMessage() {
Boolean send = false;
String myDate = getDate();
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();
// Create a DynamoDbTable object based on Employee.
DynamoDbTable<Employee> table = enhancedClient.table("Employee", TableSchema.fromBean(Employee.class));
try {
AttributeValue attVal = AttributeValue.builder().s(myDate).build();
// Get only items in the Employee table that match the date.
Map<String, AttributeValue> myMap = new HashMap<>();
myMap.put(":val1", attVal);
Map<String, String> myExMap = new HashMap<>();
myExMap.put("#startDate", "startDate");
Expression expression = Expression.builder().expressionValues(myMap).expressionNames(myExMap).expression("#startDate = :val1").build();
ScanEnhancedRequest enhancedRequest = ScanEnhancedRequest.builder().filterExpression(expression).limit(// you can increase this value.
15).build();
// Get items in the Employee table.
Iterator<Employee> employees = table.scan(enhancedRequest).items().iterator();
while (employees.hasNext()) {
Employee employee = employees.next();
String first = employee.getFirst();
String phone = employee.getPhone();
// Send an anniversary message.
sentTextMessage(first, phone);
send = true;
}
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return send;
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class PersistCase method putRecord.
// 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 Instant 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");
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class ListTables method main.
public static void main(String[] args) {
System.out.println("Your Amazon DynamoDB tables:\n");
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
listAllTables(ddb);
ddb.close();
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class PutItemEncrypt method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " PutItem <tableName> <key> <keyVal> <albumtitle> <albumtitleval> <awards> <awardsval> <Songtitle> <songtitleval>\n\n" + "Where:\n" + " tableName - the Amazon DynamoDB table in which an item is placed (for example, Music3).\n" + " key - the key used in the Amazon DynamoDB table (for example, Artist).\n" + " keyval - the key value that represents the item to get (for example, Famous Band).\n" + " albumTitle - album title (for example, AlbumTitle).\n" + " AlbumTitleValue - the name of the album (for example, Songs About Life ).\n" + " Awards - the awards column (for example, Awards).\n" + " AwardVal - the value of the awards (for example, 10).\n" + " SongTitle - the song title (for example, SongTitle).\n" + " SongTitleVal - the value of the song title (for example, Happy Day).\n" + " keyId - a KMS key id value to use to encrypt/decrypt the data (for example, xxxxxbcd-12ab-34cd-56ef-1234567890ab).";
if (args.length != 10) {
System.out.println(USAGE);
System.exit(1);
}
String tableName = args[0];
String key = args[1];
String keyVal = args[2];
String albumTitle = args[3];
String albumTitleValue = args[4];
String awards = args[5];
String awardVal = args[6];
String songTitle = args[7];
String songTitleVal = args[8];
String keyId = args[9];
Region region = Region.US_WEST_2;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
// Create a KmsClient object to use to encrpt data
KmsClient kmsClient = KmsClient.builder().region(region).build();
putItemInTable(ddb, kmsClient, tableName, key, keyVal, albumTitle, albumTitleValue, awards, awardVal, songTitle, songTitleVal, keyId);
System.out.println("Done!");
ddb.close();
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class Scenario method main.
public static void main(String[] args) throws IOException {
final String USAGE = "\n" + "Usage:\n" + " <fileName>\n\n" + "Where:\n" + " fileName - the path to the moviedata.json file that you can download from the Amazon DynamoDB Developer Guide.\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String tableName = "Movies";
String fileName = args[0];
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
System.out.println("******* Creating an Amazon DynamoDB table named Movies with a key named year and a sort key named title.");
createTable(ddb, tableName);
System.out.println("******* Loading data into the Amazon DynamoDB table.");
loadData(ddb, tableName, fileName);
System.out.println("******* Getting data from the Movie table.");
getItem(ddb);
System.out.println("******* Putting a record into the Amazon DynamoDB table.");
putRecord(ddb);
System.out.println("******* Updating a record.");
updateTableItem(ddb, tableName);
System.out.println("******* Scanning the Amazon DynamoDB table.");
scanMovies(ddb, tableName);
System.out.println("******* Querying the Movies released in 2013.");
queryTable(ddb);
System.out.println("******* Deleting the Amazon DynamoDB table.");
deleteDynamoDBTable(ddb, tableName);
ddb.close();
}
Aggregations