AWS SDK 无法识别凭证配置文件

Credentials profile file not being recognized by AWS SDK

我在使用 AWS 凭证文件时收到 key/secret 的空对象

[credentials:protected] => Aws\Common\Credentials\Credentials Object
(
    [key:protected] => 
    [secret:protected] => 
    [token:protected] => 
    [ttd:protected] => 1
)

以及

[service] => sqs
[base_url] => https://sqs.us-east-1.amazonaws.com
[key] => 
[secret] => 
[token] => 
[token.ttd] => 
[credentials.cache] => 
[credentials.cache.key] => 
[credentials.client] => 
[client.backoff] => Guzzle\Plugin\Backoff\BackoffPlugin Object
.........

我使用的代码非常简单...

Class Foo
{
    private sqsClient = null;

    public function __construct()
    {
        $this->sqsClient = SqsClient::factory([
            'profile' => 'default',
            'region'  => 'us-east-1',
        ]);

        header('content-type: text/plain'); print_r($this->sqsClient); die;
    }
}

$sqs = New Foo();

凭据和配置文件都位于 ~/.aws/{config,credentials}

配置

[default]
output = json
region = us-east-1

凭据

[default]
aws_access_key_id = XXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXX

为什么没有正确读入这些内容?这是使用 Laravel 5.0。 Composer切片如下

"require": {
    "laravel/framework": "5.0.*",
    "laravel/installer": "~1.2",
    "aws/aws-sdk-php-laravel": "~2.0",
    "aws/aws-sdk-php": "2.8.*"
},

问题是由于 ~/.aws/credentials 的文件权限属于 root 而不是用户

Laravel 默认加载 AWS 凭证,因此我们可以像下面这样使用。

    use Aws\Sqs\SqsClient;

    $sqsClient = new SqsClient([
        'region' => env('AWS_DEFAULT_REGION'),
        'version' => '2012-11-05'
    ]);