【发布时间】:2018-03-23 06:09:18
【问题描述】:
我是 S3 的新手,很难通过文件设置我的凭据。这是我目前使用硬编码凭据的有效解决方案(IAM_KEY 和 IAM_SECRET 是用于存储我的密钥的变量):
// Using hard-coded credentials
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => $IAM_KEY,
'secret' => $IAM_SECRET ,
],
]);
但是,我想将密钥和秘密存储在一个文件中,以便在我将文件推送到 GitHub 时不可见。这是我失败的尝试:
// using credential file - not working :(
$s3 = S3Client::factory(
array(
'profile' => 'my_profile',
'version' => 'latest',
'region' => 'us-east-1'
));
我的凭证文件如下:
[my_profile]
aws_access_key_id = someKey
aws_secret_access_key = someKey
我已阅读 AWS (https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html) 上的文档,但仍然卡住了。它提到我必须将我的凭证文件存储在 ~/.aws/credentials 中,但是,我找不到该目录(我需要先为 AWS 安装命令行工具吗?)。另外,凭证文件的扩展名是什么?
我已经坚持了几个小时,因此我们将不胜感激。
【问题讨论】:
标签: php amazon-web-services amazon-s3