Add doesObjectExist convenience method#7920
Conversation
848f2df to
8b4efc7
Compare
|
@RanVaknin the metadata hasn't been updated so this will only be added this github repo, and not to the AWS documentation. Is this your intention? We generally publish examples to documentation as rule. Adding metadata [INTERNAL AWS ONLY LINK] |
Hi Brian, The intention was to add it both internal and external. I was just not aware of the need to edit the metadata file. I went ahead and added an entry for this code example to the metadata file. I hope I got the format correctly (I used the entry above it as reference) Let me know if I missed anything else. Thanks, |
|
@RanVaknin You need to run WRITME to update the README in GitHub with the new example. This will deal with the WRITEME error check failure (attached) |
8641aa4 to
3690753
Compare
3690753 to
971cd2b
Compare
|
Checking changes in CDD |

Related aws/aws-sdk-java-v2#392
Background
The v1 Java SDK provided
doesObjectExist(bucket, key)as a convenience method on the S3 client. The v2 SDK does not have this. Customers must callheadObjectand catchNoSuchKeyExceptionmanually. The existing code examples repo has aDoesBucketExistexample showing the bucket equivalent, but no object example exists.This fills that gap so customers migrating from v1 have a reference for the object case.
Changes
Added code example file demonstrating how to check if an object exists in S3 using
headObject. Returns true on success, false onNoSuchKeyException, and throws on any other error (including 403).This matches v1's doesObjectExist behavior.
Added stubbed integ test. Unlike the integ test for
doesBucketExistthat uses real S3, this test uses a mock to avoid having to setup and clean resources. (I wrote a one-off integ test using real s3 just to make sure the test passes) The existing stubbed integ test should be enough to cover the behavior we are trying to showcase.