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

时间:2015-04-28 22:11:14

标签: php laravel-5 configuration-files aws-sdk

我在使用AWS凭证文件时收到密钥/机密的空对象

[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.*"
},

2 个答案:

答案 0 :(得分:0)

问题是由于~/.aws/credentials的文件权限归root用户所有

所有

答案 1 :(得分:0)

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

    use Aws\Sqs\SqsClient;

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