Skip to content
Advertisement

AWS S3 doesObjectExist costs

AWS S3 Java SDK provides a method doesObjectExist() to check if an object exists in S3. What operation does it use internally? Is it GET, LIST, or HEAD ?

My concern is mainly related to its costs. From S3 documentation the costs of US west Oregon are- PUT, COPY, POST, or LIST Requests $0.005 per 1,000 requests

GET, SELECT and all other Requests $0.0004 per 1,000 requests

Does the cost of doesObjectExist() fall under 1st or 2nd category? Also I was reading somewhere that this operation requires ListBucket and GetObject permissions. So does that mean this operation incurs cost of both the above categories?

Advertisement

Answer

Looking at the code, the doesObjectExist() method internally calls getObjectMetadata (link, link).

If you go a little deeper into the code, the actual HTTP request is a HEAD request, so I strongly suspect they are just doing a HEAD on the object itself.

The description of GetObjectMetadataRequest and the HEAD call on the REST API are also similar.

Regarding permissions, you are correct (the excerpt below also comes from the HEAD request on the REST API):

You need the s3:GetObject permission for this operation. For more information, go to Specifying Permissions in a Policy in the Amazon Simple Storage Service Developer Guide. If the object you request does not exist, the error Amazon S3 returns depends on whether you also have the s3:ListBucket permission.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement