use of com.amazonaws.services.s3.model.CreateBucketRequest in project camel by apache.
the class AmazonS3ClientMock method createBucket.
@Override
public Bucket createBucket(CreateBucketRequest createBucketRequest) throws AmazonClientException, AmazonServiceException {
if ("nonExistingBucket".equals(createBucketRequest.getBucketName())) {
nonExistingBucketCreated = true;
}
Bucket bucket = new Bucket();
bucket.setName(createBucketRequest.getBucketName());
bucket.setCreationDate(new Date());
bucket.setOwner(new Owner("c2efc7302b9011ba9a78a92ac5fd1cd47b61790499ab5ddf5a37c31f0638a8fc ", "Christian Mueller"));
return bucket;
}
use of com.amazonaws.services.s3.model.CreateBucketRequest in project nifi by apache.
the class AbstractS3IT method oneTimeSetup.
@BeforeClass
public static void oneTimeSetup() {
// Creates a client and bucket for this test
final FileInputStream fis;
try {
fis = new FileInputStream(CREDENTIALS_FILE);
} catch (FileNotFoundException e1) {
fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e1.getLocalizedMessage());
return;
}
try {
final PropertiesCredentials credentials = new PropertiesCredentials(fis);
client = new AmazonS3Client(credentials);
if (client.doesBucketExist(BUCKET_NAME)) {
fail("Bucket " + BUCKET_NAME + " exists. Choose a different bucket name to continue test");
}
CreateBucketRequest request = REGION.contains("east") ? // See https://github.com/boto/boto3/issues/125
new CreateBucketRequest(BUCKET_NAME) : new CreateBucketRequest(BUCKET_NAME, REGION);
client.createBucket(request);
} catch (final AmazonS3Exception e) {
fail("Can't create the key " + BUCKET_NAME + ": " + e.getLocalizedMessage());
} catch (final IOException e) {
fail("Caught IOException preparing tests: " + e.getLocalizedMessage());
} finally {
FileUtils.closeQuietly(fis);
}
if (!client.doesBucketExist(BUCKET_NAME)) {
fail("Setup incomplete, tests will fail");
}
}
use of com.amazonaws.services.s3.model.CreateBucketRequest in project aws-doc-sdk-examples by awsdocs.
the class CreateBucketWithACL method main.
public static void main(String[] args) throws IOException {
Regions clientRegion = Regions.DEFAULT_REGION;
String bucketName = "*** Bucket name ***";
String userEmailForReadPermission = "*** user@example.com ***";
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(clientRegion).build();
// Create a bucket with a canned ACL. This ACL will be replaced by the setBucketAcl()
// calls below. It is included here for demonstration purposes.
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName, clientRegion.getName()).withCannedAcl(CannedAccessControlList.LogDeliveryWrite);
s3Client.createBucket(createBucketRequest);
// Create a collection of grants to add to the bucket.
ArrayList<Grant> grantCollection = new ArrayList<Grant>();
// Grant the account owner full control.
Grant grant1 = new Grant(new CanonicalGrantee(s3Client.getS3AccountOwner().getId()), Permission.FullControl);
grantCollection.add(grant1);
// Grant the LogDelivery group permission to write to the bucket.
Grant grant2 = new Grant(GroupGrantee.LogDelivery, Permission.Write);
grantCollection.add(grant2);
// Save grants by replacing all current ACL grants with the two we just created.
AccessControlList bucketAcl = new AccessControlList();
bucketAcl.grantAllPermissions(grantCollection.toArray(new Grant[0]));
s3Client.setBucketAcl(bucketName, bucketAcl);
// Retrieve the bucket's ACL, add another grant, and then save the new ACL.
AccessControlList newBucketAcl = s3Client.getBucketAcl(bucketName);
Grant grant3 = new Grant(new EmailAddressGrantee(userEmailForReadPermission), Permission.Read);
newBucketAcl.grantAllPermissions(grant3);
s3Client.setBucketAcl(bucketName, newBucketAcl);
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it and returned an error response.
e.printStackTrace();
} catch (SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
}
use of com.amazonaws.services.s3.model.CreateBucketRequest in project aws-doc-sdk-examples by awsdocs.
the class CreateBucket2 method main.
public static void main(String[] args) throws IOException {
Regions clientRegion = Regions.DEFAULT_REGION;
String bucketName = "*** Bucket name ***";
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new ProfileCredentialsProvider()).withRegion(clientRegion).build();
if (!s3Client.doesBucketExistV2(bucketName)) {
// Because the CreateBucketRequest object doesn't specify a region, the
// bucket is created in the region specified in the client.
s3Client.createBucket(new CreateBucketRequest(bucketName));
// Verify that the bucket was created by retrieving it and checking its location.
String bucketLocation = s3Client.getBucketLocation(new GetBucketLocationRequest(bucketName));
System.out.println("Bucket location: " + bucketLocation);
}
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it and returned an error response.
e.printStackTrace();
} catch (SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
}
use of com.amazonaws.services.s3.model.CreateBucketRequest in project aws-doc-sdk-examples by awsdocs.
the class App method main.
public static void main(String[] args) {
if (args.length < 2) {
System.out.format("Usage: <the bucket name> <the AWS Region to use>\n" + "Example: my-test-bucket us-east-2\n");
return;
}
String bucket_name = args[0];
String region = args[1];
s3 = AmazonS3ClientBuilder.standard().withCredentials(new ProfileCredentialsProvider()).withRegion(region).build();
// List current buckets.
ListMyBuckets();
// Create the bucket.
if (s3.doesBucketExistV2(bucket_name)) {
System.out.format("\nCannot create the bucket. \n" + "A bucket named '%s' already exists.", bucket_name);
return;
} else {
try {
System.out.format("\nCreating a new bucket named '%s'...\n\n", bucket_name);
s3.createBucket(new CreateBucketRequest(bucket_name, region));
} catch (AmazonS3Exception e) {
System.err.println(e.getErrorMessage());
}
}
// Confirm that the bucket was created.
ListMyBuckets();
// Delete the bucket.
try {
System.out.format("\nDeleting the bucket named '%s'...\n\n", bucket_name);
s3.deleteBucket(bucket_name);
} catch (AmazonS3Exception e) {
System.err.println(e.getErrorMessage());
}
// Confirm that the bucket was deleted.
ListMyBuckets();
}
Aggregations