3

In general, AWS S3 works fine in my web. However, I keep getting randomly these errors when downloading:

Error retrieving credentials from the instance profile metadata server. (cURL error 28: Operation timed out after {>1000} milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html))

Why? How can I prevent these errors from happening?

I am using AWS SDK PHP v3.

Medical physicist
  • 2,510
  • 4
  • 34
  • 51
  • 1
    You can't, the internet is not 100% reliable. You can do something like retry once, then go on to other error handling. – Dave S May 31 '17 at 18:39
  • can't you just set a higher CURLOPT_TIMEOUT ? https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html – hanshenrik May 31 '17 at 21:58
  • 1
    Increasing the timeout is unlikely to help, since this question is about the **instance metadata service** (which isn't exactly "the Internet.") If this is a `t`-family instance, how is your CPU credit balance? How is your workload relative to the instance's capabilities? Is this a new problem? – Michael - sqlbot May 31 '17 at 23:44
  • Check if the response here helps. https://stackoverflow.com/questions/27400563/aws-sdk-for-php-error-retrieving-credentials-from-the-instance-profile-metadata/43250859 – omuthu Jun 01 '17 at 07:15
  • @Michael-sqlbot No, CPU credit balance is not a problem. – Medical physicist Jun 01 '17 at 10:52
  • 1
    There isn't a good reason for this to happen, unless you're overloading the metadata service with excessive requests -- that service runs on the same host (hypervisor) as your instance. It literally right there. But, I seem to recall some vague documentation about overloading it. Obviously, it's capacity isn't infinite, but I'd expect it to be adequate... and I would also expect the temporary credentials to be cached by the SDK, though I have spent very little time looking at the php SDK – Michael - sqlbot Jun 01 '17 at 12:14
  • Mention of SDKs using metadata service: http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2.html – Michael - sqlbot Jun 01 '17 at 12:17

1 Answers1

4

if are you using a Credential like below

$s3 = new Aws\S3\S3Client([
        'version' => 'latest',
        'region'  => 'us-east-1',
        'key' => "AKIAJAAAXXYASASASASDSUAG66MA",
        'secret'  => "8sZyAAAAXUSuUK3FJSDFSDS&D*SDSJFSFShjssa7Fx+GS9"
    )
]);

then change to like this

   $s3 = new Aws\S3\S3Client([
        'version' => 'latest',
        'region'  => 'us-east-1',
        'credentials' => array(
            'key' => "AKIAJAAAXXYASASASASDSUAG66MA",
            'secret'  => "8sZyAAAAXUSuUK3FJSDFSDS&D*SDSJFSFShjssa7Fx+GS9"
        )
    ]);
Nilesh patel
  • 1,216
  • 2
  • 14
  • 38
  • note they've changed it from 'key' and 'secret' to 'aws_access_key_id' and 'aws_secret_access_key' respectively – Scott Nov 08 '19 at 20:07
  • if you want to be 100% certain, create a new instance of \Aws\Credentials\Credentials for the value of 'credentials'. e.g.: 'credentials' => new Aws\Credentials\Credentials('YOURACCESSKEY','YOURSECRET') – Scott Nov 08 '19 at 20:09