It is important to know how to set AWS Access keys in Windows or Mac when we are connecting to AWS using AWS CLI.

1. Set AWS Access Keys in Windows:

AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are the programmatic credentials, which helps us to connect with the AWS using the AWS command-line interface. In Windows, we can add these secrets using the set, setx commands.

1.1 Using Set:

set AWS_ACCESS_KEY_ID=Your_Access_Key
set AWS_SECRET_ACCESS_KEY=Your_Secred_Access_Key
set AWS_DEFAULT_REGION=Your_AWS_Region

set modifies the current shell’s (the window’s) environment values, and the change is available immediately, but it is temporary.

1.2 Using Setx:

setx AWS_ACCESS_KEY_ID=Your_Access_Key 
setx AWS_SECRET_ACCESS_KEY=Your_Secred_Access_Key 
setx AWS_DEFAULT_REGION=Your_AWS_Region

setx modifies the value permanently, which affects all future shells, but does not modify the environment of the shells already running. You have to exit the shell and reopen it before the change will be available, but the value will remain modified until you change it again.

2. Set AWS Access Keys in Mac or Linux flavours:

In Mac or Linux flavours, you can set the values using the export keyword.

2.1 Using export:

export AWS_ACCESS_KEY_ID=Your_Access_Key 
export AWS_SECRET_ACCESS_KEY=Your_Secred_Access_Key 
export AWS_DEFAULT_REGION=Your_AWS_Region

export also just like set in windows, it modifies the current shell’s environment values, and the change is available immediately, but it is temporary.

2.2 Adding into bash_profile:

If you want to have permanent values in Mac or Linux environments, add the values into bash_profile.sh like below

~/.bash_profile.sh
export AWS_ACCESS_KEY_ID=Your_Access_Key 
export AWS_SECRET_ACCESS_KEY=Your_Secred_Access_Key 
export AWS_DEFAULT_REGION=Your_AWS_Region

Apply the source command to save the bash_profile.

$source ~/.bash_profile

Resources:

Happy Learning 🙂