aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.2k stars 848 forks source link

S3#bucketExists and S3#objectExists #392

Open jhovell opened 6 years ago

jhovell commented 6 years ago

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

millems commented 6 years ago

+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.

redbaron commented 5 years ago

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 :)

aiba commented 5 years ago

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.

anmgarg commented 3 years ago

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. :/

millems commented 3 years ago

To be clear: you can use the headObject method, but it's just a bit messy because you need to catch the exception if it doesn't exist.

laymain commented 2 years ago

Throwing and catching exceptions hundreds of thousands of times has a performance cost that would be good to avoid, any progress on this issue?

yehudasag commented 2 years ago

the exception is not thrown any way. is there a way to know if a bucket exist??

JoshMcCullough commented 2 years ago

Agreed with everyone above who says we need this in the Java SDK.

fatih-celonis commented 1 year ago

Yes, I also think that controlling the flow with the exception doesn't make any sense as it's an expensive operation and rather should be an "exception". +1 for having this method.