Skip to content

Add doesObjectExist convenience method#7920

Merged
brmur merged 3 commits into
awsdocs:mainfrom
RanVaknin:rvaknin/add-doesObjectExist-convenience-method-example
Jun 15, 2026
Merged

Add doesObjectExist convenience method#7920
brmur merged 3 commits into
awsdocs:mainfrom
RanVaknin:rvaknin/add-doesObjectExist-convenience-method-example

Conversation

@RanVaknin

@RanVaknin RanVaknin commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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 call headObject and catch NoSuchKeyException manually. The existing code examples repo has a DoesBucketExist example 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 on NoSuchKeyException, and throws on any other error (including 403).
    This matches v1's doesObjectExist behavior.

  • Added stubbed integ test. Unlike the integ test for doesBucketExist that 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.

@github-actions github-actions Bot added the Java-v2 This issue relates to the AWS SDK for Java V2 label Jun 3, 2026

@scmacdon scmacdon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks good , However - going to build CD

@scmacdon scmacdon added On Call Review complete On call review complete On Call Review needed This work needs an on-call review and removed On Call Review complete On call review complete labels Jun 5, 2026
@brmur brmur added the Single action example A new (or significant update to a) small example, label Jun 8, 2026
@brmur brmur force-pushed the rvaknin/add-doesObjectExist-convenience-method-example branch from 848f2df to 8b4efc7 Compare June 8, 2026 12:21
@brmur

brmur commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@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]

@scmacdon scmacdon added On Call Review needed This work needs an on-call review and removed On Call Review needed This work needs an on-call review labels Jun 9, 2026
@RanVaknin

RanVaknin commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@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,
Ran~

@brmur

brmur commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

@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)
image

@brmur brmur force-pushed the rvaknin/add-doesObjectExist-convenience-method-example branch from 8641aa4 to 3690753 Compare June 15, 2026 10:21
@brmur brmur force-pushed the rvaknin/add-doesObjectExist-convenience-method-example branch from 3690753 to 971cd2b Compare June 15, 2026 11:33
@brmur

brmur commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Checking changes in CDD

@brmur

brmur commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

CDD

@brmur brmur added On Call Review complete On call review complete and removed On Call Review needed This work needs an on-call review labels Jun 15, 2026
@brmur brmur enabled auto-merge (squash) June 15, 2026 16:18
@brmur brmur merged commit 10ac62e into awsdocs:main Jun 15, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java-v2 This issue relates to the AWS SDK for Java V2 On Call Review complete On call review complete Single action example A new (or significant update to a) small example,

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants