Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

382
Visualizações
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 Aws\Route53\Route53Client;

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

Getting this error:

Fatal error: Uncaught Aws\Exception\CredentialsException: 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?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Just remove 'profile' => 'default', and you should work fine

$client = Route53Client::factory(array(
  'region' => 'us-east-1',
  'version' => 'latest',
  'credentials' => [
        'key' => $key,
        'secret' => $secret,
  ]
));
over 4 years ago · Santiago Trujillo Relatório

0

Running on AWS Centos 7, I tried everything (chmod/chown /root /home/user, env, bashrc, etc.) to get /.aws/credentials to work outside of the apache /var/www directory. The SDK reported that it could not read the credentials file.

I looked at PHP to see if it could set/override the HOME variable and it still didn't read the credentials file until I put the .aws folder in the '/var/www' folder and set the HOME variable in my php file like so:

 <%php putenv('HOME=/var/www'); //ZIP File SDK Install requires aws-autoloader require 'aws-autoloader.php'; //Your php code below
over 4 years ago · Santiago Trujillo Relatório

0

Here is what I ended up doing for purposes of this question, although EJ's answer above is actually the right answer. Hopefully this helps someone to get their credentials file to be read:

use Aws\Credentials\CredentialProvider;
use Aws\Route53\Route53Client;

$profile = 'default';
$path = '/var/www/html/.aws/credentials';
$provider = CredentialProvider::ini($profile, $path); 
$provider = CredentialProvider::memoize($provider);

$client = Route53Client::factory(array(
    'region' => 'us-east-1',
    'version' => '2013-04-01',
    'credentials' => $provider
));
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda