Aws-sdk-java-v2: S3#bucketExists and S3#objectExists

Created on 17 Jan 2018  路  4Comments  路  Source: aws/aws-sdk-java-v2

Expected Behavior

I would expect feature parity for old 1.x methods such as AmazonS3.doesObjectExist(bucket, key). With the async client / CompletableFuture it's more than a minor annoyance as the result of S3AsyncClient.headObject(...) is to throw a NoSuchKeyException which would logically be handled in an exceptionally(throwable -> ...) stage but it is difficult to handle control flow such as letting other exceptions propagate.

Your Environment

  • AWS Java SDK version used: 2.0.0-preview-7
  • JDK version used: Oracle Java(TM) SE Runtime Environment (build 9+181)
    Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
  • Operating System and version: OSX
1.11.x Parity feature-request

Most helpful comment

most of the time checking for file/bucket existence buys you nothing, by the time you act on it it might already change it's state (be deleted, be created)

There are plenty of systems that simply never delete s3 objects, so once you check if it exists, that won't ever change.

Also in Java I believe it's generally frowned upon to throw/catch Exceptions for situations which are expected to happen.

I think it would be useful to have a doesObjectExist method.

All 4 comments

+1, there needs to be more high-level operations on the S3 client. Eg. doesBucketExist, doesObjectExist, etc.

Right now, the raw S3 operations require using exceptions for non-exceptional cases.

most of the time checking for file/bucket existence buys you nothing, by the time you act on it it might already change it's state (be deleted, be created) so unwanted state exception need to be correctly handled anyway , so whats the point of checking then :)

most of the time checking for file/bucket existence buys you nothing, by the time you act on it it might already change it's state (be deleted, be created)

There are plenty of systems that simply never delete s3 objects, so once you check if it exists, that won't ever change.

Also in Java I believe it's generally frowned upon to throw/catch Exceptions for situations which are expected to happen.

I think it would be useful to have a doesObjectExist method.

This issue is still open, so I guess this feature isn't added as of now. Correct?

I was already using the doesObjectExists in the 'aws-java-sdk-s3'. I was going to the non-blocking method but since this method doesn't exist in the java 2.x, it's a spoiler. :/

Was this page helpful?
0 / 5 - 0 ratings