Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a specified key exists in a given S3 bucket using Java

I would like to check if a key exists in a given bucket using Java. I looked at the API but there aren't any methods that are useful. I tried to use getObject but it threw an exception.

like image 314
in His Steps Avatar asked Nov 28 '11 22:11

in His Steps


People also ask

How do I find my S3 bucket key?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the bucket that you want to enable an S3 Bucket Key for. Choose Properties. In the Default encryption section, under Bucket Key, you see the S3 Bucket Key setting for your bucket.

How do you check if S3 bucket already exists?

To check whether a bucket already exists before attempting to create one with the same name, call the doesBucketExist method. It will return true if the bucket exists, and false otherwise. if (s3. doesBucketExistV2(bucket_name)) { System.

How are objects uniquely identified within an S3 bucket?

The object key (or key name) uniquely identifies the object in an Amazon S3 bucket. Object metadata is a set of name-value pairs. For more information about object metadata, see Working with object metadata. When you create an object, you specify the key name, which uniquely identifies the object in the bucket.

What is key in S3 params?

In Amazon S3, the key is the object name, or file name if your objects are files. The key is listed in the results when retrieving the contents of the bucket, and you retrieve the contents of the object by specifying the object's key . Keys in Amazon S3 must be unique.


1 Answers

There's now a doesObjectExist method in the official Java API.

Enjoy!

like image 58
malana Avatar answered Sep 24 '22 02:09

malana