JVM system properties provide another way to specify configuration options and credentials for SDKs that run on the JVM such as the AWS SDK for Java and the AWS SDK for Kotlin. For a list of JVM system properties supported by SDKs, seeSettings reference.
If you specify a setting by using its JVM system property, it overrides any value found in environment variables or loaded from a profile in the shared AWSconfig
andcredentials
files.
If you specify a setting by using its environment variable, it overrides any value loaded from a profile in the shared AWSconfig
andcredentials
files.
You can set JVM system properties several ways.
Set JVM system properties on the command-line when invoking thejava
command by using the-D
switch. The following command configures the AWS Region globally for all service clients unless you explicitly override the value in code.
java -Daws.region=us-east-1 -jar <your_application.jar> <other_arguments>
If you need to set multiple JVM system properties, specify the-D
switch multiple times.
If you can't access the command line to invoke the JVM to run your application, you can use theJAVA_TOOL_OPTIONS
environment variable to configure command-line options. This approach is useful in situations such as running an AWS Lambda function on the Java runtime or running code in an embedded JVM.
The following example configures the AWS Region globally for all service clients unless you explicitly override the value in code.
$
export JAVA_TOOL_OPTIONS="-Daws.region=us-east-1"
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.
C:\>
setx JAVA_TOOL_OPTIONS-Daws.region=us-east-1
Usingset
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. Usingsetx
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 doesnot affect other command shells that are already running at the time you run the command.
You can also set JVM system properties at runtime in code by using theSystem.setProperty
method as shown in the following example.
System.setProperty("aws.region", "us-east-1");
Set any JVM system propertiesbefore you initialize SDK service clients, otherwise service clients may use other values.