在Windows 10 WSL上访问AWS凭证:错误:在TCPConnectWrap.afterConnect上连接ECONNREFUSED 169.254.169.254:80

问题描述 投票:1回答:1

我想访问我保存在C:/Users/myusername/.aws中的AWS凭证该文件称为凭据,没有任何扩展名,并且具有我的aws_access_key_id,aws_secret_access_key和aws_session_token

下面的代码在Windows 10 WSL上不起作用,产生错误:错误:连接ECONNREFUSED 169.254.169.254:80在TCPConnectWrap.afterConnect上[完成时](net.js:1121:14)

该代码在ubuntu上有效,凭据保存在主目录的.aws文件夹中。

var AWS = require("aws-sdk");

AWS.config.getCredentials(function (err) {

if (err) console.log(err.stack);
  // credentials not loaded
else {
  console.log("Access key:", AWS.config.credentials.accessKeyId);
  console.log("Secret access key:", AWS.config.credentials.secretAccessKey);
}

});

node.js amazon-web-services amazon-s3 credentials
1个回答
0
投票
运行WSL时,C:\驱动器安装在/mnt/中。要使用Windows路径crendentials中存储的C:\Users\myusername\.aws\文件,您有两个选择:

1。使用环境变量

环境变量AWS_SHARED_CREDENTIALS_FILE必须设置为credentials文件的路径。

在WSL中:

> export AWS_SHARED_CREDENTIALS_FILE="/mnt/c/Users/myusername/.aws/credentials"

2。使用符号链接

(感谢@ Michael-sqlbot)

在WSL中:

> ln -s /mnt/c/Users/myusername/.aws ~/.aws


现在,您的Node.js应用程序应该能够访问凭据。
© www.soinside.com 2019 - 2024. All rights reserved.