JVM system properties support
JVM system properties
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
andcredentials
files. -
If you specify a setting by using its environment variable, it overrides any value loaded from a profile in the shared AWS
config
andcredentials
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.
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.