JVM system properties support - Amazon SDKs and Tools
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

JVM system properties support

JVM system properties provide another way to specify configuration options and credentials for SDKs that run on the JVM such as the Amazon SDK for Java and the Amazon SDK for Kotlin. For a list of JVM system properties supported by SDKs, see Settings reference.

Precedence of options
  • 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 AWS config and credentials files.

  • 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.

How to set JVM system properties

You can set JVM system properties several ways.

On the command line

Set JVM system properties on the command-line when invoking the java command by using the -D switch. The following command configures the Amazon Web Services 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.

With an environment variable

If you can't access the command line to invoke the JVM to run your application, you can use the JAVA_TOOL_OPTIONS environment variable to configure command-line options. This approach is useful in situations such as running an Amazon Lambda function on the Java runtime or running code in an embedded JVM.

The following example configures the Amazon Web Services Region globally for all service clients unless you explicitly override the value in code.

Linux, OS X, or Unix
$ 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.

Windows Command Prompt
C:\> setx JAVA_TOOL_OPTIONS -Daws.region=us-east-1

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.

At runtime

You can also set JVM system properties at runtime in code by using the System.setProperty method as shown in the following example.

System.setProperty("aws.region", "us-east-1");
Important

Set any JVM system properties before you initialize SDK service clients, otherwise service clients may use other values.