Search in sources :

Example 56 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project aws-doc-sdk-examples by awsdocs.

the class GetAcl method getBucketAcl.

public static void getBucketAcl(String bucket_name) {
    System.out.println("Retrieving ACL for bucket: " + bucket_name);
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {
        AccessControlList acl = s3.getBucketAcl(bucket_name);
        List<Grant> grants = acl.getGrantsAsList();
        for (Grant grant : grants) {
            System.out.format("  %s: %s\n", grant.getGrantee().getIdentifier(), grant.getPermission().toString());
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList) AmazonS3(com.amazonaws.services.s3.AmazonS3) Grant(com.amazonaws.services.s3.model.Grant) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 57 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project aws-doc-sdk-examples by awsdocs.

the class GetAcl method getObjectAcl.

public static void getObjectAcl(String bucket_name, String object_key) {
    System.out.println("Retrieving ACL for object: " + object_key);
    System.out.println("                in bucket: " + bucket_name);
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {
        AccessControlList acl = s3.getObjectAcl(bucket_name, object_key);
        List<Grant> grants = acl.getGrantsAsList();
        for (Grant grant : grants) {
            System.out.format("  %s: %s\n", grant.getGrantee().getIdentifier(), grant.getPermission().toString());
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList) AmazonS3(com.amazonaws.services.s3.AmazonS3) Grant(com.amazonaws.services.s3.model.Grant) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 58 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project aws-doc-sdk-examples by awsdocs.

the class PutObject method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket and a file to\n" + "upload to it.\n" + "\n" + "Ex: PutObject <bucketname> <filename>\n";
    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucket_name = args[0];
    String file_path = args[1];
    String key_name = Paths.get(file_path).getFileName().toString();
    System.out.format("Uploading %s to S3 bucket %s...\n", file_path, bucket_name);
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {
        s3.putObject(bucket_name, key_name, file_path);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 59 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project hippo by NHS-digital-website.

the class S3ConnectorServiceRegistrationModule method getAmazonS3.

private AmazonS3 getAmazonS3() {
    AWSCredentialsProvider provider = new SystemPropertiesCredentialsProvider();
    AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard().withCredentials(provider).withRegion(Regions.fromName(s3Region));
    if (!s3Endpoint.isEmpty()) {
        s3Builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(s3Endpoint, s3Region));
    }
    return s3Builder.build();
}
Also used : SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 60 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project aws-cf-templates by widdix.

the class ACloudFormationTest method createStack.

protected final void createStack(final String stackName, final String template, final Parameter... parameters) {
    CreateStackRequest req = new CreateStackRequest().withStackName(stackName).withParameters(parameters).withCapabilities(Capability.CAPABILITY_IAM);
    if (Config.has(Config.Key.TEMPLATE_DIR)) {
        final String dir = Config.get(Config.Key.TEMPLATE_DIR);
        if (Config.has(Config.Key.BUCKET_NAME)) {
            final String bucketName = Config.get(Config.Key.BUCKET_NAME);
            final String bucketRegion = Config.get(Config.Key.BUCKET_REGION);
            final AmazonS3 s3local = AmazonS3ClientBuilder.standard().withCredentials(this.credentialsProvider).withRegion(bucketRegion).build();
            s3local.putObject(bucketName, stackName, new File(dir + template));
            req = req.withTemplateURL("https://s3-" + bucketRegion + ".amazonaws.com/" + bucketName + "/" + stackName);
        } else {
            final String body = readFile(dir + template, Charset.forName("UTF-8"));
            req = req.withTemplateBody(body);
        }
    } else {
        req = req.withTemplateURL("https://s3-eu-west-1.amazonaws.com/widdix-aws-cf-templates/" + template);
    }
    this.cf.createStack(req);
    this.waitForStack(stackName, FinalStatus.CREATE_COMPLETE);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) File(java.io.File)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)55 AmazonServiceException (com.amazonaws.AmazonServiceException)15 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)10 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)10 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)9 Bucket (com.amazonaws.services.s3.model.Bucket)6 ArrayList (java.util.ArrayList)6 ClientConfiguration (com.amazonaws.ClientConfiguration)5 S3Object (com.amazonaws.services.s3.model.S3Object)5 Test (org.junit.Test)5 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)4 AccessControlList (com.amazonaws.services.s3.model.AccessControlList)4 Configuration (org.apache.hadoop.conf.Configuration)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)3 S3ClientOptions (com.amazonaws.services.s3.S3ClientOptions)3 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 AmazonClientException (com.amazonaws.AmazonClientException)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)2 BucketWebsiteConfiguration (com.amazonaws.services.s3.model.BucketWebsiteConfiguration)2