use of software.amazon.awssdk.regions.Region in project aws-doc-sdk-examples by awsdocs.
the class SnsService method getSnsClient.
private SnsClient getSnsClient() {
Region region = Region.US_WEST_2;
SnsClient snsClient = SnsClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
return snsClient;
}
use of software.amazon.awssdk.regions.Region 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.regions.Region in project aws-doc-sdk-examples by awsdocs.
the class AnalyzePhotos method DetectLabels.
public ArrayList DetectLabels(byte[] bytes, String key) {
Region region = Region.US_EAST_2;
RekognitionAsyncClient rekAsyncClient = RekognitionAsyncClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
try {
final AtomicReference<ArrayList<WorkItem>> reference = new AtomicReference<>();
SdkBytes sourceBytes = SdkBytes.fromByteArray(bytes);
// Create an Image object for the source image.
Image souImage = Image.builder().bytes(sourceBytes).build();
DetectLabelsRequest detectLabelsRequest = DetectLabelsRequest.builder().image(souImage).maxLabels(10).build();
CompletableFuture<DetectLabelsResponse> futureGet = rekAsyncClient.detectLabels(detectLabelsRequest);
futureGet.whenComplete((resp, err) -> {
try {
if (resp != null) {
List<Label> labels = resp.labels();
System.out.println("Detected labels for the given photo");
ArrayList list = new ArrayList<WorkItem>();
WorkItem item;
for (Label label : labels) {
item = new WorkItem();
// identifies the photo
item.setKey(key);
item.setConfidence(label.confidence().toString());
item.setName(label.name());
list.add(item);
}
reference.set(list);
} else {
err.printStackTrace();
}
} finally {
// Only close the client when you are completely done with it
rekAsyncClient.close();
}
});
futureGet.join();
// Use the AtomicReference object to return the ArrayList<WorkItem> collection.
return reference.get();
} catch (RekognitionException e) {
System.out.println(e.getMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.regions.Region in project aws-doc-sdk-examples by awsdocs.
the class ListClusters method main.
public static void main(String[] args) {
Region region = Region.US_WEST_2;
EmrClient emrClient = EmrClient.builder().region(region).build();
listAllClusters(emrClient);
emrClient.close();
}
use of software.amazon.awssdk.regions.Region in project aws-doc-sdk-examples by awsdocs.
the class DeleteRule method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <ruleName> \n\n" + "Where:\n" + " ruleName - the name of the rule to delete. \n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String ruleName = args[0];
Region region = Region.US_WEST_2;
EventBridgeClient eventBrClient = EventBridgeClient.builder().region(region).build();
deleteEBRule(eventBrClient, ruleName);
eventBrClient.close();
}
Aggregations