Example usage for com.amazonaws.services.s3.model CreateBucketRequest CreateBucketRequest

List of usage examples for com.amazonaws.services.s3.model CreateBucketRequest CreateBucketRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model CreateBucketRequest CreateBucketRequest.

Prototype

public CreateBucketRequest(String bucketName, String region) 

Source Link

Document

Constructs a new CreateBucketRequest , ready to be executed and create the specified bucket in the specified region.

Usage

From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java

License:MIT License

/**
 * ?/*from  w w  w .ja v a2  s.  co  m*/
 *
 * @param bucketName
 * @return s3client
 * @throws StoreException
 * @throws Exception
 */
private AmazonS3 getS3Client(String bucketName) throws StoreException {
    logger.debug("get S3 Client start.");
    // ?
    AWSCredentialsProvider provider = new EnvironmentVariableCredentialsProvider();

    // 
    ClientConfiguration clientConfig = new ClientConfiguration()

            // .withProtocol(Protocol.HTTPS) // Proxy
            // .withProxyHost("proxyHost")
            // .withProxyPort(80)
            // .withProxyUsername("proxyUsername")
            // .withProxyPassword("proxyPassword")

            .withConnectionTimeout(10000);

    // ?
    AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(provider)
            .withClientConfiguration(clientConfig).withRegion(DEFAULT_REGION)
            .withForceGlobalBucketAccessEnabled(true).build();

    logger.debug("Region={}", s3client.getRegion());

    try {
        // ??
        if (!CommonUtils.isNullOrEmpty(bucketName) && !(s3client.doesBucketExistV2(bucketName))) {
            s3client.createBucket(new CreateBucketRequest(bucketName, DEFAULT_REGION.getName()));
        }
        // Get location.
        String bucketLocation = s3client.getBucketLocation(new GetBucketLocationRequest(bucketName));
        logger.info("bucket location={}", bucketLocation);
    } catch (AmazonClientException ace) {
        throw new StoreException(HttpStatus.SC_CONFLICT, ErrorClassification.BS0003, ace, "?");
    }

    logger.info("get S3 Client end.");
    return s3client;
}

From source file:nl.nn.adapterframework.filesystem.AmazonS3FileSystem.java

License:Apache License

/**
* Creates a bucket on Amazon S3./*from  w  w  w.j  av  a 2s .c o  m*/
*
* @param bucketName
*            The desired name for a bucket that is about to be created. The class {@link BucketNameUtils} 
*            provides a method that can check if the bucketName is valid. This is done just before the bucketName is used here.
* @param bucketExistsThrowException
*            This parameter is used for controlling the behavior for whether an exception has to be thrown or not. 
*            In case of upload action being configured to be able to create a bucket, an exception will not be thrown when a bucket with assigned bucketName already exists.
*/
public String createBucket(String bucketName, boolean bucketExistsThrowException) throws SenderException {
    try {
        if (!s3Client.doesBucketExistV2(bucketName)) {
            CreateBucketRequest createBucketRequest = null;
            if (isForceGlobalBucketAccessEnabled())
                createBucketRequest = new CreateBucketRequest(bucketName, getBucketRegion());
            else
                createBucketRequest = new CreateBucketRequest(bucketName);
            s3Client.createBucket(createBucketRequest);
            log.debug("Bucket with bucketName: [" + bucketName + "] is created.");
        } else if (bucketExistsThrowException)
            throw new SenderException(" bucket with bucketName [" + bucketName
                    + "] already exists, please specify a unique bucketName");

    } catch (AmazonServiceException e) {
        log.warn("Failed to create bucket with bucketName [" + bucketName + "].");
        throw new SenderException("Failed to create bucket with bucketName [" + bucketName + "]." + e);
    }

    return bucketName;
}

From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserServiceImpl.java

License:Apache License

@Override
public void createBucket(String bucketName, String region) {
    CreateBucketRequest request = new CreateBucketRequest(bucketName, region);
    this.s3.createBucket(request);
}

From source file:org.mule.module.s3.simpleapi.SimpleAmazonS3AmazonDevKitImpl.java

License:Open Source License

public Bucket createBucket(@NotNull String bucketName, Region region, CannedAccessControlList acl) {
    Validate.notNull(bucketName);/* w w  w  .java2 s.  c  o m*/
    CreateBucketRequest request = new CreateBucketRequest(bucketName, region.toS3Equivalent());
    request.setCannedAcl(acl);
    return s3.createBucket(request);
}

From source file:org.plos.repo.service.S3StoreService.java

License:Open Source License

@Override
public Optional<Boolean> createBucket(Bucket bucket) {
    try {//from   w  ww.  j  a v a  2 s.c  o m
        CreateBucketRequest bucketRequest = new CreateBucketRequest(bucket.getBucketName(), Region.US_West);
        bucketRequest.withCannedAcl(CannedAccessControlList.PublicRead);
        s3Client.createBucket(bucketRequest);

        return TRUE;
    } catch (Exception e) {
        log.error("Error creating bucket", e);
        return FALSE;
    }
}