Running AWS CLI WITH SSO on WSL2

Hopefully Microsoft AppStore is not blocked, so installing WSL is not an issue. Mine was blocked so I had to do this:

Skip this step if you can install WSL2 from AppStore or it is already installed.

# run Powershell as Administrator

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# restart your Windows box
# I enabled my VPN
wsl --install -d Ubuntu-22.04
set version to wls2
wsl --set-version <distro name> 2 replacing <distro name> with the name of the Linux distribution that you want to update. For example, wsl --set-version Ubuntu-20.04 2 will set your Ubuntu 20.04
or simply:
wsl --set-default-version 2
# Download and run kernel update - wsl_update_x64.msi

Prerequisite: AWS CLI is installed on Windows

Make aws sso work with Windows and WSL2 on ubuntu 22.04

— if pip is not installed – you might have to:
sudo apt-get update after that Run sudo apt install python3-pip

install awscli2 — make SURE it is V2 of the awscli
Here is one way to do that on ubuntu wsl2

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

check the version with this:

aws --version # should show v2

add these two lines to your wsl2 .bashrc – to share the windows .aws/config with WSL – after you installed aws cli

export AWS_SHARED_CREDENTIALS_FILE=/mnt/c/Users//.aws/credentials
export AWS_CONFIG_FILE=/mnt/c/Users//.aws/config

cat .bashrc | grep -i aws_
export AWS_SHARED_CREDENTIALS_FILE=/mnt/c/Users//.aws/credentials
export AWS_CONFIG_FILE=/mnt/c/Users//.aws/config

— it’s easier to do the “aws sso login –profile
— now use the same profile you did originally on Windows
— but it does work to aws sso login from WSL2 – just clutsier… stick to sso on windows

aws s3 ls –profile nonamedev

2023-10-12 15:42:14 noname-sf-prd
2023-03-24 21:20:23 noname-sftp-prd
2023-09-28 11:49:10 noname-sftp-prd
2023-09-05 11:31:43 noname-transformed
2023-01-13 18:53:39 nonamepub
2023-10-05 15:35:16 redshifty
2023-10-31 09:49:43 tf-state
doesn’t matter than your bash userid does not match your windows, cuz you are using your windows config file

and as a bonus install terminal if Microsoft AppStore is blocked with this:

winget install --id Microsoft.WindowsTerminal -e
Scroll to Top