【发布时间】: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