Trying to instantiate ec2client w.r.t
$ec2Client = \Aws\Ec2\Ec2Client::factory(array(
'profile' => 'default',
'region' => 'us-west-2',
'version' => '2014-10-01'
));
but fails with error
Uncaught exception 'Aws\Common\Exception\CredentialsException' with message 'Could not load credentials.'
I have :
cat ~/.aws/credentials
[default]
aws_access_key_id = xxxxxxxxxxx
aws_secret_access_key = xxxxxxxxxxx
I am using aws-sdk through composer "aws/aws-sdk-php": "3.*@dev"
.
Edit 1): I am trying this on my local development machine.
Edit 2): I tried this:
use Aws\Common\Credentials\InstanceProfileProvider;
$profile= new InstanceProfileProvider(['profile'=>'default']);
$ec2Client = \Aws\Ec2\Ec2Client::factory(array(
'region' => 'us-west-2',
'version' =>'2014-10-01',
'credentials' => $profile
));
This gives me different error :
'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 error 28: Connection timed out after 1000 milliseconds)' in .. /InstanceProfileProvider.php:9 ..
This gives me the impression that credential profiles are only when application running from within the AWS cloud instance ! Which makes the idea of profiles useless (which where intended for dev environment )
Edit 3)
After debugging this, It seems that sdk with credential profiles is broken or not as expected . Both credential profiles
and environment variable
both depends on environment variables . If environment variables are disabled, both will fail.
Possible work around:
a) Enable environment variables
b) Set HOME evn variable
putenv('HOME=/Users/yourname');
$ec2Client = \Aws\Ec2\Ec2Client::factory(array(
'region' => 'us-west-2',
'version' => '2014-10-01'
));
Profile init()
function has filename option but there is not apparent way to pass credentails profile path other than HOME env
variable
Aws\Common\Credentails\Profiler->init()
public static function ini($profile = null, $filename = null){
...
}
Again if you are unable to read the /Users/yourname/.aws/credentials
file you have to tweak it little bit
chmod 644 /Users/yourname/.aws/credentials