title: Getting file size from S3 bucket
body: <p>I am trying to get the file size (content-length) using Amazon S3 JAVA sdk.</p>
  
  <pre><code>public Long getObjectSize(AmazonS3Client amazonS3Client, String bucket, String key)
          throws IOException {
      Long size = null;
      S3Object object = null;
      try {
          object = amazonS3Client.getObject(bucket, key);
          size = object.getObjectMetadata().getContentLength();
  
      } finally {
          if (object != null) {
              //object.close();
              1. This results in 50 calls (connection pool size) post that I start getting connection pool errors. 
              2. If this line is uncommented it takes hell lot of time to make calls.
          }
      }
      return size;
  }
  </code></pre>
  
  <p>I followed <a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingJava.html" rel="noreferrer">this</a> and <a href="https://stackoverflow.com/questions/20233259/how-to-close-aws-connection-if-there-is-no-such-key-in-the-query">this</a>. But not sure what I am doing wrong here.
  Any help on this?</p>