【问题标题】:Unable to get aws credentials from IAM role无法从 IAM 角色获取 aws 凭证
【发布时间】:2015-09-22 17:31:18
【问题描述】:

我正在使用 SDK 版本 2.8.21 来使用 KMS。

我有一个 config.php 文件,其中包含

<?php

// File saved as /path/to/custom/config.php
require 'vendor/autoload.php';

use Doctrine\Common\Cache\FilesystemCache;
use Guzzle\Cache\DoctrineCacheAdapter;

// Create a cache adapter that stores data on the filesystem
$cacheAdapter = new DoctrineCacheAdapter(new FilesystemCache('/tmp/cache'));

return array(
    'includes' => array('_aws'),
    'services' => array(
        'default_settings' => array(
            'params' => array(
                'credentials.cache' => $cacheAdapter
            )
        )
    )
);

下面是我用来做测试加密的test.php文件。

<?php

  require 'vendor/autoload.php';

  use Aws\Common\Aws;

  // Create the AWS service builder, providing the path to the config file
  try {

    $keyId = '<KMSKEYALIAS>';

    $aws = Aws::factory('config.php');
    $client = $aws->get('kms');

    $result = $client->encrypt(array(
      'KeyId' => $keyId,
      'Plaintext' => 'This is the song that never ends...'
    ));

    print_r($result);

  }
  catch (\Exception $e)
  {
    echo $e->getMessage()."\n\n";
  }

当我执行 php test.php 时,我得到“使用 AWS Key Management Service 时需要一个区域”。

认为这可能是我们使用 CLI 工具测试的服务器 IAM 问题。

aws kms encrypt --key-id <KMSKEYALIAS> --plaintext "1\!2@3#4$5%6^7&8*9(0)-_=+" --query CiphertextBlob --output text | base64 --decode > /tmp/encrypt.txt

并且 /tmp/encrypted.txt 包含加密数据。

我很茫然,真的可以使用一些帮助来确定这是 aws 中的错误还是我做错了什么。

我目前无法升级到 v3.x,因为我们使用的是 php 5.4,并且现在无法升级到 5.5。

【问题讨论】:

标签: php amazon-web-services


【解决方案1】:

正如@cmorrissey 所说,我需要设置区域。我阅读的文档和博客文章并没有说明这一点。这个答案是为了以防其他人发现文档不够清楚。

<?php

// File saved as /path/to/custom/config.php
require 'vendor/autoload.php';

use Doctrine\Common\Cache\FilesystemCache;
use Guzzle\Cache\DoctrineCacheAdapter;

// Create a cache adapter that stores data on the filesystem
$cacheAdapter = new DoctrineCacheAdapter(new FilesystemCache('/tmp/cache'));

return array(
    'includes' => array('_aws'),
    'services' => array(
        'default_settings' => array(
            'params' => array(
                'region' => 'us-east-1',
                'credentials.cache' => $cacheAdapter
            )
        )
    )
);

【讨论】:

    猜你喜欢
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 2021-09-26
    相关资源
    最近更新 更多