title: AWS Lambda function extremely slow to retrieve S3 file
body: <p>I have a Lambda function that needs to read a file from S3 every time it is executed.<br>
  The file is very small, about 200 bytes, the S3 bucket is in the US Standard region, the Lambda function is in the us-east-1 region (so the same region). It takes between 10 and 15 seconds to read the file, how come this is so slow?  </p>
  
  <p>Thanks.  </p>
  
  <p>EDIT: some code</p>
  
  <pre><code>long start = System.nanoTime();
  AmazonS3Client s3Client = new AmazonS3Client();
  S3Object propertyFile = null;
  try {
      propertyFile = s3Client.getObject(S3_BUCKET_NAME, S3_PROPERTY_FILE);
  } catch (Exception e) {...}
  try (InputStream in = propertyFile.getObjectContent()) {
      PROPERTIES.load(in);
  } catch (Exception e) {...}
  LOGGER.debug("S3 access " + (System.nanoTime() - start));
  </code></pre>
  
  <p>EDIT #2: After Brooks' suggestion I did</p>
  
  <pre><code>AmazonS3Client s3Client = new AmazonS3Client(new InstanceProfileCredentialsProvider());
  </code></pre>
  
  <p>And I get this error:</p>
  
  <pre><code>Unable to load credentials from Amazon EC2 metadata service
  </code></pre>
  
  <p>EDIT #3:<br>
  The memory allocated to the Lambda function was 256MB, when I allocate 1024MB, it takes 3-4 seconds which is still too slow (it takes about 1-2 seconds when I test locally from my computer).</p>