As a best practice, we recommend that you don't embed access keys directly into code. The AWS SDKs and the AWS Command Line Tools enable you to put access keys in known locations so that you do not have to keep them in code. Put access keys in one of the following locations:
Environment variables – On a multitenant system, choose user environment variables, not system environment variables.
CLI credentials file – The
credentials
andconfig
file are updated when you run the commandaws configure
. Thecredentials
file is located at~/.aws/credentials
on Linux, macOS, or Unix, or atC:\Users\
on Windows. This file can contain the credential details for theUSERNAME
\.aws\credentialsdefault
profile and any named profiles.CLI configuration file – The
credentials
andconfig
file are updated when you run the commandaws configure
. Theconfig
file is located at~/.aws/config
on Linux, macOS, or Unix, or atC:\Users\
on Windows. This file contains the configuration settings for the default profile and any named profiles.USERNAME
\.aws\config
Storing access keys as environment variables is a prerequisite for the Step-by-step tutorial to connect to Amazon Keyspaces using the 4.x DataStax Java driver for Apache Cassandra and the SigV4 authentication plugin. Note that this includes the default AWS Region. The client searches for credentials using the default credentials provider chain, and access keys stored as environment variables take precedent over all other locations, for example configuration files. For more information, see Configuration settings and precedence.
The following examples show how you can configure environment variables for the default user.
$
export AWS_ACCESS_KEY_ID=
AKIAIOSFODNN7EXAMPLE
$
export AWS_SECRET_ACCESS_KEY=
wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
$
export AWS_SESSION_TOKEN=
AQoDYXdzEJr...<remainder of security token>
$
export AWS_DEFAULT_REGION=
aws-region
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.