I am trying to send SNS messeges to android through web api. Downloaded and installed the SDK from http://aws.amazon.com/developers/getting-started/php/
Got following error while running sample.php:
Fatal error: Uncaught exception 'Aws\Common\Exception\InstanceProfileCredentialsException' with message 'Error retrieving credentials from the instance profile metadata server. When you are not running inside of Amazon EC2, you must provide your AWS access key ID and secret access key in the "key" and "secret" options when creating a client or provide an instantiated Aws\Common\Credentials\CredentialsInterface object. ([curl] 28: Connection timed out after 5016 milliseconds [url] http://169.254.169.254/latest/meta-data/iam/security-credentials/)' in C:\xampp\htdocs\aws-php\vendor\aws\aws-sdk-php\src\Aws\Common\InstanceMetadata\InstanceMetadataClient.php:85 Stack trace: #0 C:\xampp\htdocs\aws-php\vendor\aws\aws-sdk-php\src\Aws\Common\Credentials\RefreshableInstanceProfileCredentials.php(52): Aws\Common\InstanceMetadata\InstanceMetadataClient->getInstanceProfileCredentials() #1 C:\xampp\htdocs\aws-php\vendor\aws\aws-sdk-php\src\Aws\Common\Credentials\AbstractRefreshableCredentials.php(54): Aws\Common\Credentials\Refreshable in C:\xampp\htdocs\aws-php\vendor\aws\aws-sdk-php\src\Aws\Common\InstanceMetadata\InstanceMetadataClient.php on line 85
A little guidance on this topic will help me a lot
In my case, I was using
return DynamoDbClient::factory(array(
'version' => 'latest',
'region' => AWS_REGION,
'key' => AWS_KEY,
'secret' => AWS_SECRET
));
which used to be ok with aws/aws-sdk-php
version 2.8.5 , but when composer automatically installed version 3.2.0, I got the error above. The problem is simply that I should've changed the way I made the call to
return DynamoDbClient::factory(array(
'version' => 'latest',
'region' => AWS_REGION,
'credentials' => array(
'key' => AWS_KEY,
'secret' => AWS_SECRET,
)
));
as documented here. Without changing the call, the apache php was falling back to looking for the ~/.aws/credentials
file using the HOME environment variable, which was empty. You can check its value by running php -r 'var_dump(getenv("HOME"));'
.
This is a related post
In my case I had to use hard-coded credentials
$s3Client = new S3Client([
'region' => REGION,
'version' => '2006-03-01',
'credentials' => [
'key' => S3_KEY,
'secret' => S3_SECRETE,
],
]);
See more details here:
You have to place the .aws/credentials
file with your configuration in the home directory of the web service *usually /var/www
) not in the home directory of the logged in user.
You can find what home directory you web service is using by running echo getenv('HOME');
in a php file on your server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With