Movatterモバイル変換


[0]ホーム

URL:


Using JVM system properties to globally configure AWS SDK for Java and AWS SDK for Kotlin - AWS SDKs and Tools
DocumentationReference Guide
How to set JVM system properties

Using JVM system properties to globally configure AWS SDK for Java and AWS SDK for Kotlin

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.

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

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

With an environment variable

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.

Linux, macOS, 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

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.

At runtime

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");
Environment variables
Authentication and access

[8]
ページ先頭

©2009-2025 Movatter.jp