Search in sources :

Example 46 with Region

use of software.amazon.awssdk.regions.Region in project aws-doc-sdk-examples by awsdocs.

the class SetAcl method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "  <bucketName> <id> \n\n" + "Where:\n" + "  bucketName - the Amazon S3 bucket to grant permissions on. \n" + "  id - the ID of the owner of this bucket (you can get this value from the AWS Management Console).\n";
    if (args.length != 3) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    String id = args[1];
    System.out.format("Setting access \n");
    System.out.println(" in bucket: " + bucketName);
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder().region(region).build();
    setBucketAcl(s3, bucketName, id);
    System.out.println("Done!");
    s3.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 47 with Region

use of software.amazon.awssdk.regions.Region in project aws-doc-sdk-examples by awsdocs.

the class SetBucketPolicy method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <bucketName> <polFile>\n\n" + "Where:\n" + "    bucketName - the Amazon S3 bucket to set the policy on.\n" + "    polFile - a JSON file containing the policy (see the Amazon S3 Readme for an example). \n";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    String polFile = args[1];
    String policyText = getBucketPolicyFromFile(polFile);
    Region region = Region.US_EAST_1;
    S3Client s3 = S3Client.builder().region(region).build();
    setPolicy(s3, bucketName, policyText);
    s3.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 48 with Region

use of software.amazon.awssdk.regions.Region in project aws-doc-sdk-examples by awsdocs.

the class CreateBucketAsync method main.

public static void main(String[] args) throws URISyntaxException {
    final String USAGE = "\n" + "Usage:\n" + "    <bucketName> \n\n" + "Where:\n" + "    bucketName - the name of the bucket to create. The bucket name must be unique, or an error occurs.\n\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    System.out.format("Creating a bucket named %s\n", bucketName);
    Region region = Region.US_EAST_1;
    S3AsyncClient s3AsyncClient = S3AsyncClient.builder().region(region).build();
    createBucket(s3AsyncClient, bucketName);
}
Also used : Region(software.amazon.awssdk.regions.Region) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient)

Example 49 with Region

use of software.amazon.awssdk.regions.Region in project aws-doc-sdk-examples by awsdocs.

the class S3AsyncOps method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    S3AsyncOps <bucketName> <key> <path>\n\n" + "Where:\n" + "    bucketName - the name of the Amazon S3 bucket (for example, bucket1). \n\n" + "    key - the name of the object (for example, book.pdf). \n" + "    path - the local path to the file (for example, C:/AWS/book.pdf). \n";
    if (args.length != 3) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    String key = args[1];
    String path = args[2];
    Region region = Region.US_WEST_2;
    S3AsyncClient client = S3AsyncClient.builder().region(region).build();
    PutObjectRequest objectRequest = PutObjectRequest.builder().bucket(bucketName).key(key).build();
    // Put the object into the bucket
    CompletableFuture<PutObjectResponse> future = client.putObject(objectRequest, AsyncRequestBody.fromFile(Paths.get(path)));
    future.whenComplete((resp, err) -> {
        try {
            if (resp != null) {
                System.out.println("Object uploaded. Details: " + resp);
            } else {
                // Handle error
                err.printStackTrace();
            }
        } finally {
            // Only close the client when you are completely done with it
            client.close();
        }
    });
    future.join();
}
Also used : PutObjectResponse(software.amazon.awssdk.services.s3.model.PutObjectResponse) Region(software.amazon.awssdk.regions.Region) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient)

Example 50 with Region

use of software.amazon.awssdk.regions.Region in project aws-doc-sdk-examples by awsdocs.

the class ListAlgorithms method main.

public static void main(String[] args) {
    Region region = Region.US_WEST_2;
    SageMakerClient sageMakerClient = SageMakerClient.builder().region(region).build();
    listAlgs(sageMakerClient);
    sageMakerClient.close();
}
Also used : SageMakerClient(software.amazon.awssdk.services.sagemaker.SageMakerClient) 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