【问题标题】:PHP AWS AssumeRole with InstanceProfile throws Exception带有 InstanceProfile 的 PHP AWS AssumeRole 抛出异常
【发布时间】:2020-09-29 21:59:26
【问题描述】:

试图让这段代码工作。我们已经设置好了,所以我们不需要从文件中读取凭据。但它仍在寻找它们。

$provider = \Aws\Credentials\CredentialProvider::instanceProfile();
call_user_func( $provider )->wait();
$config = [
        'profile' => 'default',
        'region' => 'us-east-1',
        'version' => '2011-06-15',
        'credentials' => $provider,
        'http' => [
            'connect_timeout' => 30,  // By default these wait indefinitely
            'timeout' => 60,
        ]
    ];
try {
    $stsClient = new StsClient($config);
    $stsResult = $stsClient->assumeRole([
            'RoleArn' => 'arn:aws:iam::1234:role/my-role',
            'RoleSessionName' => 'MySession'
        ]);
} catch (\Exception $e) {
   echo 'Caught exception: ',  $e->getMessage(), "\n";
}

但它不是从实例中获取它,而是抛出异常:

 Cannot read credentials from /home/user/.aws/credentials

【问题讨论】:

    标签: php amazon-ec2


    【解决方案1】:

    删除

    'profile' => 'default',
    

    从配置中。使用这意味着它将始终尝试从文件系统中读取凭据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      相关资源
      最近更新 更多