Environment variables support
Environment variables provide another way to specify configuration options and
credentials, and can be useful for scripting or temporarily setting a named profile as the
default.
Precedence of options
-
If you specify a setting by using its environment variable, it overrides any value loaded from a profile in the shared AWS config
and credentials
files.
-
If you specify a setting by using a parameter on the AWS CLI command line, it
overrides any value from either the corresponding environment variable or a profile
in the configuration file.
How to set environment variables
The following examples show how you can configure environment variables for the
default user.
- Linux, macOS, or Unix
-
$
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
$
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
$
export AWS_DEFAULT_REGION=us-west-2
Setting the environment variable changes the value used until the end of
your shell session, or until you set the variable to a different value. You
can make the variables persistent across future sessions by setting them in
your shell's startup script.
- Windows Command Prompt
-
C:\>
setx AWS_ACCESS_KEY_ID AKIAIOSFODNN7EXAMPLE
C:\>
setx AWS_SECRET_ACCESS_KEY wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
C:\>
setx AWS_DEFAULT_REGION us-west-2
Using set
to set an environment variable changes the value used until the end of the current
Command Prompt session, or until you set the variable to a different value. Using setx
to set an environment variable changes the value used in both the current Command
Prompt session and all Command Prompt sessions that you create after running the command. It does not affect other command shells that are already
running at the time you run the command.
- PowerShell
-
PS C:\>
$Env:AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE
"
PS C:\>
$Env:AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
"
PS C:\>
$Env:AWS_DEFAULT_REGION="us-west-2
"
If you set an environment variable at the PowerShell prompt as shown in
the previous examples, it saves the value for only the duration of the
current session. To make the environment variable setting persistent across
all PowerShell and Command Prompt sessions, store it by using the
System application in Control
Panel. Alternatively, you can set the variable for all future
PowerShell sessions by adding it to your PowerShell profile. See the PowerShell documentation for more information about storing
environment variables or persisting them across sessions.