title: Getting a reference to a specific Bucket via AmazonS3Client
body: <p>While I was trying to upload objects to a specific <strong>bucket</strong> in Amazon S3 storage via Amazon Web Services API, I obviously needed a reference to that existing bucket. I was using <code>AmazonS3Client</code> to perform that, however I couldn't see any method such as <code>getBucket(String bucketID)</code>. </p>
  
  <p>Please check here: <a href="http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Client.html" rel="nofollow">AmazonS3Client</a> </p>
  
  <p>I applied a brute-force search to get a reference to the desired bucket: </p>
  
  <pre><code>AmazonS3Client connection = new AmazonS3Client(credentials);
  Bucket targetBucket = null;
  
  List&lt;Bucket&gt; buckets = connection.listBuckets();
  for (Bucket bucket : buckets)
  {
    if (bucket.getName().equals(bucketId))
    {
      targetBucket = bucket;
      break;
    }
  }
  </code></pre>
  
  <p>Obviously, this works fine. But I wonder why the API doesn't provide such a trivial method or might I be missing something or do you know any other method(s) from the same API which will replace the lines above with one-line code?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>For a simple task like uploading a file, the bucket name seems to be sufficient:</p>
  
  <pre><code>if (connection.doesBucketExist(bucketId))
  {
    connection.putObject(bucketId, ... );
  }
  </code></pre>
  
  <p>However, my question is as the title implies, why isn't there a method returning a reference to a specific <code>Bucket</code> instance?</p>