AWS

How set AWS Access Keys in Windows or Mac Environment

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.

1.3 Powershell:

$env:AWS_ACCESS_KEY_ID="Your_Access_Key"
$env:AWS_SECRET_ACCESS_KEY="Your_Secred_Access_Key"

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

2.3 Adding into aws credentials file

$ ~/.aws/credentials
[default]
aws_access_key_id=Your_Access_Key
aws_secret_access_key= Your_Secred_Access_Key 

Resources:

Happy Learning :)

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Ask a question or leave a comment

Our product

Preparing for an AWS, Azure or Google Cloud exam?

Take a free 20-question sample test with an explanation for every answer. No sign-up needed.

Start the free test