List of usage examples for com.amazonaws.services.s3 AmazonS3Client createBucket
@Override public Bucket createBucket(CreateBucketRequest createBucketRequest) throws SdkClientException, AmazonServiceException
From source file:io.klerch.alexa.state.handler.AWSS3StateHandlerIT.java
License:Open Source License
@BeforeClass public static void createBucket() { // credentials need to be set in local environment // see http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html final AmazonS3Client amazonS3Client = new AmazonS3Client(); amazonS3Client.createBucket(bucketName); }
From source file:it.polimi.modaclouds.cpimlibrary.blobmng.AmazonBlobManager.java
License:Apache License
public AmazonBlobManager(AmazonS3Client s3) { if (this.bucketName == null) { try {//from w w w.j av a 2 s.c o m Properties endpoints = new Properties(); if (this.getClass().getResourceAsStream("/endpoints.properties") != null) { endpoints.load(this.getClass().getResourceAsStream("/endpoints.properties")); if (endpoints.getProperty("S3") != null) this.bucketName = endpoints.getProperty("S3").toLowerCase(Locale.ENGLISH); } if (this.bucketName == null) this.bucketName = "mycloudapplicationbucket"; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } this.s3 = s3; if (!s3.doesBucketExist(bucketName)) { System.out.println("Creating bucket " + bucketName + "\n"); s3.createBucket(bucketName); } }
From source file:n3phele.storage.s3.CloudStorageImpl.java
License:Open Source License
public boolean createBucket(Repository repo) throws ForbiddenException { Credential credential = repo.getCredential().decrypt(); AmazonS3Client s3 = new AmazonS3Client( new BasicAWSCredentials(credential.getAccount(), credential.getSecret())); s3.setEndpoint(repo.getTarget().toString()); try {/* w ww.ja v a 2 s.c o m*/ try { s3.listObjects(new ListObjectsRequest(repo.getRoot(), null, null, null, 0)); // it exists and the current account owns it return false; } catch (AmazonServiceException ase) { switch (ase.getStatusCode()) { case 403: /* * A permissions error means the bucket exists, but is owned by * another account. */ throw new ForbiddenException( "Bucket " + repo.getRoot() + " has already been created by another user."); case 404: Bucket bucket = s3.createBucket(repo.getRoot()); log.info("Bucket created " + bucket.getName()); return true; default: throw ase; } } } catch (AmazonServiceException e) { log.log(Level.WARNING, "Service Error processing " + repo, e); } catch (AmazonClientException e) { log.log(Level.SEVERE, "Client Error processing " + repo, e); } return false; }
From source file:org.apache.usergrid.tools.WarehouseExport.java
License:Apache License
private void copyToS3(String fileName) { String bucketName = (String) properties.get(BUCKET_PROPNAME); String accessId = (String) properties.get(ACCESS_ID_PROPNAME); String secretKey = (String) properties.get(SECRET_KEY_PROPNAME); Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); final Iterable<? extends Module> MODULES = ImmutableSet.of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); AWSCredentials credentials = new BasicAWSCredentials(accessId, secretKey); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTP); AmazonS3Client s3Client = new AmazonS3Client(credentials, clientConfig); s3Client.createBucket(bucketName); File uploadFile = new File(fileName); PutObjectResult putObjectResult = s3Client.putObject(bucketName, uploadFile.getName(), uploadFile); logger.info("Uploaded file etag={}", putObjectResult.getETag()); }
From source file:org.broadleafcommerce.vendor.amazon.s3.S3FileServiceProvider.java
License:Apache License
/** * Writes the resource to S3. If the bucket returns as "NoSuchBucket" then will attempt to create the bucket * and try again./*w w w . j a va 2s. c o m*/ */ @Override public List<String> addOrUpdateResourcesForPaths(FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) { S3Configuration s3config = s3ConfigurationService.lookupS3Configuration(); AmazonS3Client s3 = getAmazonS3Client(s3config); try { return addOrUpdateResourcesInternal(s3config, s3, workArea, files, removeFilesFromWorkArea); } catch (AmazonServiceException ase) { if ("NoSuchBucket".equals(ase.getErrorCode())) { s3.createBucket(s3config.getDefaultBucketName()); return addOrUpdateResourcesInternal(s3config, s3, workArea, files, removeFilesFromWorkArea); } else { throw new RuntimeException(ase); } } }
From source file:org.broadleafcommerce.vendor.amazon.s3.S3FileServiceProvider.java
License:Apache License
public void addOrUpdateResource(InputStream inputStream, String fileName, long fileSizeInBytes) { S3Configuration s3config = s3ConfigurationService.lookupS3Configuration(); AmazonS3Client s3 = getAmazonS3Client(s3config); try {//from w ww . j a v a 2 s. c om addOrUpdateResourcesInternalStreamVersion(s3config, s3, inputStream, fileName, fileSizeInBytes); } catch (AmazonServiceException ase) { if ("NoSuchBucket".equals(ase.getErrorCode())) { s3.createBucket(s3config.getDefaultBucketName()); addOrUpdateResourcesInternalStreamVersion(s3config, s3, inputStream, fileName, fileSizeInBytes); } else { throw new RuntimeException(ase); } } }
From source file:org.entando.entando.plugins.jps3awsclient.aps.system.services.storage.AmazonS3StorageManager.java
License:Open Source License
public void checkForAndCreateBucket(String bucketName, AmazonS3Client client) { // Make sure it's lower case to comply with Amazon S3 recommendations bucketName = bucketName.toLowerCase(); if (this._bucketMap.get(bucketName) == null) { if (client.doesBucketExist(bucketName)) { this._bucketMap.put(bucketName, true); } else {// w w w .j a v a2s .c o m // Bucket hasn't been created yet so we create it CreateBucketRequest request = new CreateBucketRequest(bucketName); request.withCannedAcl(CannedAccessControlList.LogDeliveryWrite); client.createBucket(request); this._bucketMap.put(bucketName, true); } } }
From source file:org.geowebcache.s3.S3BlobStoreInfo.java
License:Open Source License
/** @return {@link AmazonS3Client} constructed from this {@link S3BlobStoreInfo}. */ public AmazonS3Client buildClient() { ClientConfiguration clientConfig = new ClientConfiguration(); if (null != useHTTPS) { clientConfig.setProtocol(useHTTPS ? Protocol.HTTPS : Protocol.HTTP); }//w w w . ja va2s . c o m if (null != maxConnections && maxConnections > 0) { clientConfig.setMaxConnections(maxConnections); } clientConfig.setProxyDomain(proxyDomain); clientConfig.setProxyWorkstation(proxyWorkstation); clientConfig.setProxyHost(proxyHost); if (null != proxyPort) { clientConfig.setProxyPort(proxyPort); } clientConfig.setProxyUsername(proxyUsername); clientConfig.setProxyPassword(proxyPassword); if (null != useGzip) { clientConfig.setUseGzip(useGzip); } log.debug("Initializing AWS S3 connection"); AmazonS3Client client = new AmazonS3Client(getCredentialsProvider(), clientConfig); if (endpoint != null && !"".equals(endpoint)) { S3ClientOptions s3ClientOptions = new S3ClientOptions(); s3ClientOptions.setPathStyleAccess(true); client.setS3ClientOptions(s3ClientOptions); client.setEndpoint(endpoint); } if (!client.doesBucketExist(bucket)) { client.createBucket(bucket); } return client; }
From source file:org.kuali.maven.wagon.S3Wagon.java
License:Educational Community License
protected Bucket getOrCreateBucket(AmazonS3Client client, String bucketName) { List<Bucket> buckets = client.listBuckets(); for (Bucket bucket : buckets) { if (bucket.getName().equals(bucketName)) { return bucket; }/*from w ww . ja va2s. c o m*/ } return client.createBucket(bucketName); }
From source file:org.wildfly.camel.test.common.aws.S3Utils.java
License:Apache License
@SuppressWarnings("unchecked") public static void createBucket(AmazonS3Client client, String bucketName) throws Exception { client.createBucket(bucketName); HeadBucketRequest request = new HeadBucketRequest(bucketName); Waiter<HeadBucketRequest> waiter = client.waiters().bucketExists(); Future<Void> future = waiter.runAsync(new WaiterParameters<HeadBucketRequest>(request), new NoOpWaiterHandler()); future.get(1, TimeUnit.MINUTES); }