thedreamsaver
thedreamsaver

Reputation: 1384

How to access aws config file from WSL (Windows subsystem for Linux)?

I have installed awscli and have added aws keys to the config and credentials file. Now I can access them through file explorer from Windows but I cannot access them through the WSL bash. It says permission denied when I try to cd to the .aws folder present in rootfs. How do I access them from bash?

Upvotes: 16

Views: 17463

Answers (2)

Garret Wilson
Garret Wilson

Reputation: 21356

It would seem to me that setting AWS_SHARED_CREDENTIALS_FILE and AWS_CONFIG_FILE, as explained in the other answer, is the most elegant approach. However I just now followed the AWS CLI Linux installation instructions, which say to use the following commands, which executes a downloaded script:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

The script must have detected that I was running in WSL, because apparently it created a WSL symlink of ~/.aws to /mnt/c/Users/user/.aws, which has equivalent results to using the environment variables. And since this approach is reasonable as well, I don't feel there's a need to use the energy to switch to the environment variable approach.

Note: I'm not entirely certain that the awscliv2.zip installer made these changes. I first tried installing the AWS CLI in WSL using sudo apt install awscli before realizing that it installed v1.x instead of v2.x, so I uninstalled it and used the approach described here. Maybe someone can verify the behavior and confirm in the comments what command added the symlink.

Upvotes: 2

DaMightyMouse
DaMightyMouse

Reputation: 822

All you have to do is to set a couple of environment variables from the WSL shell. I am assuming that you are working with bash and Ubuntu.

export AWS_SHARED_CREDENTIALS_FILE=/mnt/c/Users/<your user name>/.aws/credentials
export AWS_CONFIG_FILE=/mnt/c/Users/<your user name>/.aws/config

If you want to make the env variables sticky add the two lines to ~/.bashrc or /etc/bash.bashrc

remember to source /etc/bash.bashrc or source ~/.bashrc after editing them.

See documentation here complete list of env variables you can work with cli-environment

Upvotes: 48

Related Questions