Kalyani Wani
Kalyani Wani

Reputation: 33

Can we perform, creating a bucket, block public access and bucket versioning functionality in single java SDK call in Amazon S3?

I'm trying to create a bucket with the additional functionality of the "Block public access" setting and bucket versioning enable/disable through JAVA SDK. But the problem that I'm facing is that all the functionalities are given in different classes of JAVA, which is problematic because if one of the requests is executed and the other is not, then it will cause the operation to be half performed or executed. So my question is that can we perform all the above-given functionalities in a single JAVA SDK call?

For creating a bucket on Amazon S3, I'm using the following code -

CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucket);
s3Object.createBucket(createBucketRequest.withObjectLockEnabledForBucket(Boolean.parseBoolean(objectLock)));

Please note that Object Lock functionality is given in the call.

Thanks in advance.

Upvotes: 0

Views: 166

Answers (1)

luk2302
luk2302

Reputation: 57124

No, you cannot do that. The underlying S3 CreateBucket API (which each and every SDK uses) simply does not offer that.

You may want to "outsource" the bucket creation e.g. into a dedicated lambda that can be retried and write your code in a way that it can skip the bucket creation if it already exists and then try to set the versioning, etc.

Upvotes: 1

Related Questions