Accessing AWS credentials on Windows 10 WSL : Error: connect ECONNREFUSED 169.254.169.254:80 at TCPConnectWrap.afterConnect

Viewed 4682

I want to access my AWS credentials that I saved in C:/Users/myusername/.aws The file is called credentials without any extension and it has my aws_access_key_id, aws_secret_access_key and aws_session_token

The code below does not work on windows 10 WSL,producing error : Error: connect ECONNREFUSED 169.254.169.254:80 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1121:14)

The code works on ubuntu, with the credentials saved in .aws folder in the home directory.

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);
}

});

1 Answers

When running WSL, the C:\ drive is mounted in /mnt/. To use the crendentials file stored in the Windows path C:\Users\myusername\.aws\, you have two options:

1. Using an environment variable

The environment variable AWS_SHARED_CREDENTIALS_FILE has to be set to the path of the credentials file.

In WSL:

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

2. Using a symlink

(Thanks to @Michael-sqlbot)

In WSL:

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

Now, your Node.js application should be able to access the credentials.

Related