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);
}
}
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);
}
}
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!");
}
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();
}
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);
}
Aggregations