从 php 执行 AWS CLI 命令导致无法找到凭证 [英] Executing AWS CLI command from php results in Unable to locate credentials
本文介绍了从 php 执行 AWS CLI 命令导致无法找到凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 shell exec 从 php 代码中运行 aws s3 cp 命令.以下是php代码.
I am trying to run aws s3 cp command from within php code using shell exec. Following is the php code.
echo shell_exec("sudo aws s3 cp s3://<bucket>/somefolder/somefile s3://<bucket>/someotherfolder/somefile --region ap-southeast-1 --acl public-read");
文件没有被复制,echo 的输出如下
The file is not getting copied and The output from echo is the following
无法找到凭据已完成 1 部分,还有……文件"
"Unable to locate credentials Completed 1 part(s) with ... file(s) remaining"
注意 1:我已经使用 aws configure 命令设置了凭据
注 2:如果我直接从终端运行完全相同的命令,它工作正常.
有什么想法吗?
推荐答案
这对我有用:
<?php
putenv('AWS_DEFAULT_REGION=your-region');
putenv('AWS_ACCESS_KEY_ID=YOURACCESSKEYID');
putenv('AWS_SECRET_ACCESS_KEY=YOURSECRETACCESSKEY');
$output = shell_exec('aws s3 cp ./file.txt s3://MYBUCKETID/ 2>&1');
echo "<pre>$output</pre>";
?>
这篇关于从 php 执行 AWS CLI 命令导致无法找到凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文