com.amazonaws.services.s3.model.CreateBucketRequest Java Examples
The following examples show how to use
com.amazonaws.services.s3.model.CreateBucketRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: S3Utils.java From amazon-kinesis-connectors with Apache License 2.0 | 6 votes |
/** * Create an Amazon S3 bucket if it does not exist. * * @param client * The {@link AmazonS3Client} with read and write permissions * @param bucketName * The bucket to create * @throws IllegalStateException * The bucket is not created before timeout occurs */ public static void createBucket(AmazonS3Client client, String bucketName) { if (!bucketExists(client, bucketName)) { CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName); createBucketRequest.setRegion(Region.US_Standard.toString()); client.createBucket(createBucketRequest); } long startTime = System.currentTimeMillis(); long endTime = startTime + 60 * 1000; while (!bucketExists(client, bucketName) && endTime > System.currentTimeMillis()) { try { LOG.info("Waiting for Amazon S3 to create bucket " + bucketName); Thread.sleep(1000 * 10); } catch (InterruptedException e) { } } if (!bucketExists(client, bucketName)) { throw new IllegalStateException("Could not create bucket " + bucketName); } LOG.info("Created Amazon S3 bucket " + bucketName); }
Example #2
Source File: AwsFileSystem.java From judgels with GNU General Public License v2.0 | 5 votes |
public AwsFileSystem(AwsConfiguration config, AwsFsConfiguration fsConfig) { AWSCredentials creds = new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey()); this.s3 = AmazonS3ClientBuilder .standard() .withRegion(config.getS3BucketRegionId()) .withCredentials(new AWSStaticCredentialsProvider(creds)) .build(); this.cloudFrontBaseUrl = config.getCloudFrontBaseUrl(); this.bucketName = fsConfig.getS3BucketName(); if (!s3.doesBucketExistV2(bucketName)) { s3.createBucket(new CreateBucketRequest(bucketName, Region.fromValue(config.getS3BucketRegionId()))); } }
Example #3
Source File: S3.java From lambadaframework with MIT License | 5 votes |
/** * Creates new bucket if not existing * * @param bucket Bucket * @param region Region * @return true on success, false on failure */ public static boolean createBucketIfNotExists(String bucket, String region) { if (getS3Client().doesBucketExist(bucket)) { return false; } getS3Client().createBucket(new CreateBucketRequest(bucket, region)); return true; }
Example #4
Source File: TestUtil.java From datacollector with Apache License 2.0 | 5 votes |
public static void createBucket(AmazonS3 s3client, String bucketName) { if(s3client.doesBucketExist(bucketName)) { for(S3ObjectSummary s : S3Objects.inBucket(s3client, bucketName)) { s3client.deleteObject(bucketName, s.getKey()); } s3client.deleteBucket(bucketName); } Assert.assertFalse(s3client.doesBucketExist(bucketName)); // Note that CreateBucketRequest does not specify region. So bucket is // bucketName s3client.createBucket(new CreateBucketRequest(bucketName)); }
Example #5
Source File: DummyS3Client.java From ignite with Apache License 2.0 | 4 votes |
/** Unsupported Operation. */ @Override public Bucket createBucket(CreateBucketRequest createBucketReq) throws SdkClientException { throw new UnsupportedOperationException("Operation not supported"); }
Example #6
Source File: BucketClass.java From cloudExplorer with GNU General Public License v3.0 | 4 votes |
String makeBucket(String access_key, String secret_key, String bucket, String endpoint, String region) { String message = null; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { s3Client.setEndpoint(endpoint); if (region.length() > 5) { if (region.contains("us-east-1")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (region.contains("us-west")) { s3Client.setEndpoint("https://s3-" + region + ".amazonaws.com"); } else if (region.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + region + ".amazonaws.com"); } else if (region.contains("ap-")) { s3Client.setEndpoint("https://s3-" + region + ".amazonaws.com"); } else if (region.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + region + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + region + ".amazonaws.com"); } } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } message = ("\nAttempting to create the bucket. Please view the Bucket list window for an update."); try { if (!(s3Client.doesBucketExist(bucket))) { s3Client.createBucket(new CreateBucketRequest(bucket)); } String bucketLocation = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); } catch (AmazonServiceException ase) { if (ase.getMessage().contains("InvalidLocationConstraint")) { s3Client.createBucket(new CreateBucketRequest(bucket, region)); } else { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } } return message; }
Example #7
Source File: AmazonS3Mock.java From Scribengin with GNU Affero General Public License v3.0 | 4 votes |
@Override public Bucket createBucket(CreateBucketRequest createBucketRequest) throws AmazonClientException, AmazonServiceException { // TODO Auto-generated method stub return null; }
Example #8
Source File: CrossRegionReplication.java From aws-doc-sdk-examples with Apache License 2.0 | 3 votes |
private static void createBucket(AmazonS3 s3Client, Regions region, String bucketName) { CreateBucketRequest request = new CreateBucketRequest(bucketName, region.getName()); s3Client.createBucket(request); BucketVersioningConfiguration configuration = new BucketVersioningConfiguration().withStatus(BucketVersioningConfiguration.ENABLED); SetBucketVersioningConfigurationRequest enableVersioningRequest = new SetBucketVersioningConfigurationRequest(bucketName, configuration); s3Client.setBucketVersioningConfiguration(enableVersioningRequest); }