Skip to content
Advertisement

Cannot read credentials from /.aws/credentials – PHP script call AWS-SDK

I’ve looked at every answer on here and it seems my problem is a little different or there hasn’t been a proper solution. I’m doing the following in my PHP file:

use AwsRoute53Route53Client;

$client = Route53Client::factory(array(
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => '2013-04-01'
));

Getting this error:

Fatal error: Uncaught AwsExceptionCredentialsException: Cannot read credentials from /.aws/credentials

Seems like the easy fix would be ensure that the HOME directory is the right one. Indeed it already is. Files are readable and my ec2-user is already the owner. Key and Secret is already installed in the ‘credentials’ file. Profile name is already set to ‘default.’ Tried to copy /.aws to other directories such as the root, /home, etc and changed permissions, chmod, all the above. Still nothing.

Then I tried to hard-code the credentials (I know — not recommended) just to give it a little kick, and it completely ignores that I did this:

$client = Route53Client::factory(array(
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => '2013-04-01',
    'credentials' => [
            'key' => $key,
            'secret' => $secret,
    ]
));

As a last resort, I even tried including the CredentialProvider class, and passing this into my array — still nothing:

'credentials' => CredentialProvider::ini('default', '/home/ec2-user/.aws/credentials'),

What on earth am I doing wrong?

Advertisement

Answer

Not sure what you are doing wrong, but I’d suggest bypassing the problem altogether and assigning an EC2 Instance role to the vm in question and then you won’t have to worry about it; it’s a better/more secure solution.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement