本文整理汇总了Java中com.amazonaws.services.s3.model.CreateBucketRequest类的典型用法代码示例。如果您正苦于以下问题:Java CreateBucketRequest类的具体用法?Java CreateBucketRequest怎么用?Java CreateBucketRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CreateBucketRequest类属于com.amazonaws.services.s3.model包,在下文中一共展示了CreateBucketRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addIAMHeaders
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
/**
* Add IAM specific headers based on the credentials set & any optional
* parameters added to the CreateBucketRequest object
*
* @param request
* @param createBucketRequest
* @return Request<CreateBucketRequest>
*/
protected Request<CreateBucketRequest> addIAMHeaders(Request<CreateBucketRequest> request, CreateBucketRequest createBucketRequest){
if ((null != this.awsCredentialsProvider ) && (this.awsCredentialsProvider.getCredentials() instanceof IBMOAuthCredentials)) {
if (null != createBucketRequest.getServiceInstanceId()) {
request.addHeader(Headers.IBM_SERVICE_INSTANCE_ID, createBucketRequest.getServiceInstanceId());
} else {
IBMOAuthCredentials oAuthCreds = (IBMOAuthCredentials)this.awsCredentialsProvider.getCredentials();
if (oAuthCreds.getServiceInstanceId() != null) {
request.addHeader(Headers.IBM_SERVICE_INSTANCE_ID, oAuthCreds.getServiceInstanceId());
}
}
}
return request;
}
示例2: createBucket
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
/**
* Create an amazon bucket in the specified region
* @param bucket - The s3 bucket name
* @param region - The S3 region the bucket should be created in
* @param accessList - The access control list settings for the bucket
*/
public void createBucket(final String bucket,
final Region region,
final CannedAccessControlList cannedACL,
final AccessControlList accessList){
final CreateBucketRequest request = new CreateBucketRequest(bucket, region);
if(cannedACL!=null){
request.withCannedAcl(cannedACL);
}
if(accessList!=null){
request.withAccessControlList(accessList);
}
this.client.createBucket(request);
}
示例3: createBucket
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
@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;
}
示例4: testServiceInstanceRuntimeParamTakesPrecedence
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
/**
* Test Service Instance Id is added to the Request Object and
* the runtime parameter takes precedence over any set by the
* CredentialProvider
*
*/
@Test
public void testServiceInstanceRuntimeParamTakesPrecedence() {
String serviceInstanceId = "12345";
CreateBucketRequest request = new CreateBucketRequest("testbucket").withServiceInstanceId(serviceInstanceId);
Request<CreateBucketRequest> defaultRequest = new DefaultRequest(Constants.S3_SERVICE_DISPLAY_NAME);
AmazonS3Client s3Client = new AmazonS3Client(new BasicIBMOAuthCredentials(new TokenMangerUtilTest(), "54321"));
defaultRequest = s3Client.addIAMHeaders(defaultRequest, request);
assertEquals(defaultRequest.getHeaders().get(Headers.IBM_SERVICE_INSTANCE_ID), serviceInstanceId);
}
示例5: testServiceInstanceHeaderIsAddedByCredentialProvdier
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
/**
* Test Service Instance Id is added to the Request Object by
* the CredentialProvider
*
*/
@Test
public void testServiceInstanceHeaderIsAddedByCredentialProvdier() {
String serviceInstanceId = "12345";
CreateBucketRequest request = new CreateBucketRequest("testbucket");
Request<CreateBucketRequest> defaultRequest = new DefaultRequest(Constants.S3_SERVICE_DISPLAY_NAME);
AmazonS3Client s3Client = new AmazonS3Client(new BasicIBMOAuthCredentials(new TokenMangerUtilTest(), serviceInstanceId));
defaultRequest = s3Client.addIAMHeaders(defaultRequest, request);
assertEquals(defaultRequest.getHeaders().get(Headers.IBM_SERVICE_INSTANCE_ID), serviceInstanceId);
}
示例6: testNoIAMHeadersAreAdded
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
/**
* Test No IAM Headers are added & no null pointers are thrown
*
*/
@Test
public void testNoIAMHeadersAreAdded() {
CreateBucketRequest request = new CreateBucketRequest("testbucket");
Request<CreateBucketRequest> defaultRequest = new DefaultRequest(Constants.S3_SERVICE_DISPLAY_NAME);
AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials("987654321", "123456789"));
defaultRequest = s3Client.addIAMHeaders(defaultRequest, request);
assertEquals(defaultRequest.getHeaders().get(Headers.IBM_SERVICE_INSTANCE_ID), null);
}
示例7: createBucketIfNotExists
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
/**
* 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;
}
示例8: createS3BucketIfNotExist
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
public void createS3BucketIfNotExist(String bucketName, String regionName, boolean isOutputBucket) throws TranscodeException{
s3client.setRegion(Region.getRegion(Regions.fromName(regionName)));
try {
if(!(s3client.doesBucketExist(bucketName)))
{
// Note that CreateBucketRequest does not specify region. So bucket is
// created in the region specified in the client.
s3client.createBucket(new CreateBucketRequest(
bucketName));
}
if (isOutputBucket){
String policyText = "{"
+ "\"Id\": \"1\","
+ "\"Version\": \"2012-10-17\","
+ "\"Statement\": ["
+ " {"
+ " \"Sid\": \"1\","
+ " \"Action\": ["
+ " \"s3:GetObject\""
+ " ],"
+ " \"Effect\": \"Allow\","
+ " \"Resource\": \"arn:aws:s3:::"+bucketName+"/*\","
+ " \"Principal\": \"*\""
+ " }"
+ "]"
+ "}";
SetBucketPolicyRequest setBucketPolicyRequest = new SetBucketPolicyRequest(bucketName, policyText);
s3client.setBucketPolicy(setBucketPolicyRequest);
}
} catch (AmazonServiceException ase) {
logger.error("Caught an AmazonServiceException, which " +
"means your request made it " +
"to Amazon S3, but was rejected with an error response" +
" for some reason.", ase);
throw new TranscodeException(ase.getMessage());
} catch (AmazonClientException ace) {
logger.error("Caught an AmazonClientException, which " +
"means the client encountered " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.", ace);
throw new TranscodeException(ace.getMessage());
} catch (IllegalArgumentException ie) {
logger.error("Couldn't get the region", ie);
throw new TranscodeException(ie.getMessage());
}
}
示例9: createBucket
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
@Override
public Bucket createBucket(final String bucketName, final CannedAccessControlList cannedAcl)
throws AmazonClientException, AmazonServiceException {
LOGGER.info("createBucket invoked, bucketName: {} and cannedAccessControlList: {}",bucketName,cannedAcl);
final CreateBucketRequest createBucketReq = new CreateBucketRequest(bucketName).withCannedAcl(cannedAcl);
return s3client.createBucket(createBucketReq);
}
示例10: createBucket
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
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));
}
示例11: createBucket
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
@Override
public Optional<Boolean> createBucket(Bucket bucket) {
try {
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;
}
}
示例12: main
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
public static void main(String[] args) {
if (!S3.doesBucketExist(S3_BUCKET_NAME)) {
S3.createBucket(new CreateBucketRequest(S3_BUCKET_NAME));
}
System.out.println("Using Amazon S3 Bucket: " + S3_BUCKET_NAME);
}
示例13: main
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
CreateBucketRequest createBucketRequest = new CreateBucketRequest(AWSResources.S3_BUCKET_NAME);
try {
AWSResources.S3.createBucket(createBucketRequest);
System.out.println("Bucket Created...");
}
catch (AmazonS3Exception ex){
if(!ex.getErrorCode().equals(createBucketRequest)) {
throw ex;
}
}
}
示例14: createBucket
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
@Override
public Bucket createBucket(CreateBucketRequest createBucketRequest) throws AmazonClientException, AmazonServiceException {
return delegate.createBucket(createBucketRequest);
}
示例15: createBucket
import com.amazonaws.services.s3.model.CreateBucketRequest; //导入依赖的package包/类
@Override
public Bucket createBucket(String bucketName)
throws SdkClientException, AmazonServiceException {
return createBucket(new CreateBucketRequest(bucketName));
}