Search in sources :

Example 81 with Region

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;
}
Also used : SnsClient(software.amazon.awssdk.services.sns.SnsClient) Region(software.amazon.awssdk.regions.Region)

Example 82 with Region

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");
}
Also used : LocalDateTime(java.time.LocalDateTime) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) Instant(java.time.Instant) Region(software.amazon.awssdk.regions.Region) LocalDate(java.time.LocalDate) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Example 83 with Region

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;
}
Also used : RekognitionAsyncClient(software.amazon.awssdk.services.rekognition.RekognitionAsyncClient) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) SdkBytes(software.amazon.awssdk.core.SdkBytes) Region(software.amazon.awssdk.regions.Region)

Example 84 with Region

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();
}
Also used : EmrClient(software.amazon.awssdk.services.emr.EmrClient) Region(software.amazon.awssdk.regions.Region)

Example 85 with Region

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();
}
Also used : EventBridgeClient(software.amazon.awssdk.services.eventbridge.EventBridgeClient) Region(software.amazon.awssdk.regions.Region)

Aggregations

Region (software.amazon.awssdk.regions.Region)534 S3Client (software.amazon.awssdk.services.s3.S3Client)43 RekognitionClient (software.amazon.awssdk.services.rekognition.RekognitionClient)32 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)31 IamClient (software.amazon.awssdk.services.iam.IamClient)23 PersonalizeClient (software.amazon.awssdk.services.personalize.PersonalizeClient)22 Ec2Client (software.amazon.awssdk.services.ec2.Ec2Client)20 Test (org.junit.Test)17 AwsCredentialsProvider (software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)15 KmsClient (software.amazon.awssdk.services.kms.KmsClient)15 URI (java.net.URI)13 CodeCommitClient (software.amazon.awssdk.services.codecommit.CodeCommitClient)13 GlueClient (software.amazon.awssdk.services.glue.GlueClient)12 Properties (java.util.Properties)11 DynamoDbEnhancedClient (software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)11 SesClient (software.amazon.awssdk.services.ses.SesClient)11 SdkBytes (software.amazon.awssdk.core.SdkBytes)9 Route53Client (software.amazon.awssdk.services.route53.Route53Client)9 CloudTrailClient (software.amazon.awssdk.services.cloudtrail.CloudTrailClient)8 CloudWatchClient (software.amazon.awssdk.services.cloudwatch.CloudWatchClient)8