Amazon Web Services (AWS) command-line interface (CLI) supports specific environment variables. These environment variables are listed at Environment variables to configure the AWS CLI
In python scripts using the AWS boto3 library, there is a list of environment variables that are used by the library.
If using AWS_SESSION_TOKEN
, a session will need to be created and environment variable values will need to use the session information.
-
Get session information from AWS and place into
~/aws-sts-get-session-token.json
file. Example:aws sts get-session-token \ > ~/aws-sts-get-session-token.json
-
✏️ Identify the AWS multi-factor authentication serial number for the device supplying the MFA token. Registered devices can be found at AWS My security credentials Example:
export AWS_MFA_SERIAL_NUMBER="arn:aws:iam::nnnnnnnnnnnn:mfa/xxxxxxxx"
If defined in
~/.aws/config
, run:export AWS_MFA_SERIAL_NUMBER=$(aws configure get default.mfa_serial)
-
✏️ Get MFA token from the device supplying the MFA token. It is usually a 6-digit number. Note: This token is short lived; perhaps only one minute duration. So the step performed after this step must be performed immediately afterwards to use a valid token value. Example:
export AWS_MFA_TOKEN_CODE=nnnnnn
-
Get session information from AWS and place into
~/aws-sts-get-session-token.json
file. Example:aws sts get-session-token \ --serial-number ${AWS_MFA_SERIAL_NUMBER} \ --token-code ${AWS_MFA_TOKEN_CODE} \ > ~/aws-sts-get-session-token.json
-
Pull information from
~/.aws/credentials
Example:export AWS_ACCESS_KEY_ID=$(aws configure get default.aws_access_key_id)
-
For a session, pull information from
~/aws-sts-get-session-token.json
, a file created in the AWS Session section. Example:export AWS_ACCESS_KEY_ID=$(jq --raw-output ".Credentials.AccessKeyId" ~/aws-sts-get-session-token.json)
-
References:
-
Pull information from
~/.aws/config
Example:export AWS_DEFAULT_REGION=$(aws configure get default.region)
-
References:
-
Pull information from
~/.aws/credentials
Example:export AWS_SECRET_ACCESS_KEY=$(aws configure get default.aws_secret_access_key)
-
For a session, pull information from
~/aws-sts-get-session-token.json
, a file created in the AWS Session section. Example:export AWS_SECRET_ACCESS_KEY=$(jq --raw-output ".Credentials.SecretAccessKey" ~/aws-sts-get-session-token.json)
-
References:
-
For a session, pull information from
~/aws-sts-get-session-token.json
, a file created in the AWS Session section. Example:export AWS_SESSION_TOKEN=$(jq --raw-output ".Credentials.SessionToken" ~/aws-sts-get-session-token.json)
-
References:
-
Pull information from
~/.aws/config
Example:export AWS_MFA_SERIAL_NUMBER=$(aws configure get default.mfa_serial)
-
✏️ Get MFA token from the device supplying the MFA token. Note: This token is short lived; perhaps only one minute duration. So the step performed after this step must be performed immediately afterwards to use a valid token value. Example:
export AWS_MFA_TOKEN_CODE=nnnnnn