Hi! When i try using aws-php-sdk i see this error:
http://169.254.169.254/latest/meta-data/iam/security-credentials/): failed to open stream:
please help me
Are you using an EC2 instance?
no, ec3
Do you mean S3?
Make sure you're providing credentials to your application. This can be done in several ways, such as by setting environment variables, placing them in an ini file, and passing them in directly when constructing a client. When no credentials are provided in the client constructor, the SDK will first look for credentials in the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and then for an ini file at ~/.aws/credentials. If no credentials have been found by that point, the SDK will attempt to contact the EC2 instance metadata service, which is the operation you see failing.
yes s3, but not help
my code
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-west-2'
]);
// Upload a publicly accessible file. The file size and type are determined by the SDK.
try {
$s3->putObject([
'Bucket' => '.....t',
'Key' => '.....',
'Body' => fopen('c:\\test.txt', 'r'),
'ACL' => 'public-read',
]);
} catch (Aws\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n";
}
This problem reproduced after today update aws-php-sdk
How are you supplying credentials to the SDK?
in the IAM console.
So this code _is_ running on an Ec2 instance?
i do not know, i try only for s3, 2 weeks ago, everything worked and ip 169.254.169.254 not ping
The fact that the instance metadata service is unreachable indicates that your code is not running on an Ec2 instance. This means that you will need to find a way to provide credentials to the instance of S3Client, either by passing them in directly or by setting up an ini file or environment variables as described here.
It's possible that everything was working before because the appropriate environment variables were being set by Apache or Nginx or because there was an ini file at ~/.aws/credentials that has since been removed.
Thanks, I'll try and accomplish your goal
Most helpful comment
Do you mean S3?
Make sure you're providing credentials to your application. This can be done in several ways, such as by setting environment variables, placing them in an ini file, and passing them in directly when constructing a client. When no credentials are provided in the client constructor, the SDK will first look for credentials in the
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYand then for an ini file at~/.aws/credentials. If no credentials have been found by that point, the SDK will attempt to contact the EC2 instance metadata service, which is the operation you see failing.