使用 RStudio 找不到 AWS-CLI 凭据,但在 Windows CLI 中工作正常

AWS-CLI credentials not found using RStudio, but works fine from Windows CLI

当我从 windows 命令行发出 AWS-CLI 命令时,"aws s3 ls" 它成功完成。当我尝试 shell(paste0("aws ", "s3 ", "ls")) 将 R 与 Eclipse 结合使用时,它成功完成。

然而,在另一台使用相同凭据的机器上,从 windows 命令行,"aws s3 ls" 成功完成,但使用 RStudio shell(paste0("aws ", "s3 ", "ls")) 我得到:

"fatal error: Unable to locate credentials"

如果我从 RStudio 运行 shell(paste0("aws ", "s3 ", "ls ", "--debug")) 我得到:

2017-02-27 15:07:10,516 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: env 2017-02-27 15:07:10,516 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role 2017-02-27 15:07:10,516 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: shared-credentials-file 2017-02-27 15:07:10,516 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: config-file 2017-02-27 15:07:10,516 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: ec2-credentials-file 2017-02-27 15:07:10,516 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: boto-config 2017-02-27 15:07:10,516 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: container-role 2017-02-27 15:07:10,516 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: iam-role 2017-02-27 15:07:10,520 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - INFO - Starting new HTTP connection (1): xxx.xxx.xxx.xxx 2017-02-27 15:07:10,523 - MainThread - botocore.utils - DEBUG - Caught exception while trying to retrieve credentials: ('Connection aborted.', error(10051, 'A socket operation was attempted to an unreachable network')) Traceback (most recent call last): File "botocore\utils.pyc", line 159, in _get_request File "botocore\vendored\requests\api.pyc", line 69, in get File "botocore\vendored\requests\api.pyc", line 50, in request File "botocore\vendored\requests\sessions.pyc", line 465, in request File "botocore\vendored\requests\sessions.pyc", line 573, in send File "botocore\vendored\requests\adapters.pyc", line 415, in send

对于 Windows 命令行的成功案例,它会找到如下所示的凭据:

2017-02-27 15:07:03,267 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: env 2017-02-27 15:07:03,267 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role 2017-02-27 15:07:03,267 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: shared-credentials-file 2017-02-27 15:07:03,267 - MainThread - botocore.credentials - INFO - Found credentials in shared credentials file: ~/.aws/credentials

所以,我想弄清楚的是为什么 AWS CLI 无法使用 RStudio 找到凭证,但它在 Windows CLI 中工作正常。

更新:我在两台机器上都安装了 Eclipse,并且运行良好。但是,它仍然无法与 RStudio 一起使用,因此它一定是一个与 IDE 相关的问题。有什么想法吗?

我能够通过在 RStudio 中定义 AWS 凭证来解决它:

Sys.setenv ("AWS_ACCESS_KEY_ID" = "YourKEY_ID",
           "AWS_SECRET_ACCESS_KEY" = "YOURSECRETACCESSKEY",
           "AWS_DEFAULT_REGION" = "eu-west-1")