All Products
Search
Document Center

Enterprise Distributed Application Service:Obtain custom environment variables from an application

Last Updated:Feb 27, 2026

On Enterprise Distributed Application Service (EDAS), you can define custom environment variables on the application server and access them at runtime from your application code.

Prerequisites

Before you begin, make sure that you have:

  • An EDAS application deployed on an Elastic Compute Service (ECS) instance

  • SSH access to the application server

  • The admin account credentials

Procedure

  1. Log on to the application server and switch to the admin account:

       su - admin
  2. Open the ~/.bash_profile file and add your custom environment variables. For example: Save the file and exit the editor.

       export API_ENDPOINT="https://api.example.com"
       export DB_HOST="rm-xxxxxxx.mysql.rds.aliyuncs.com"
  3. Load the environment variables into the current session:

       source ~/.bash_profile
  4. Access the environment variables from your application code. Call methods such as System.getenv() to obtain the custom environment variables. For example:

       String endpoint = System.getenv("API_ENDPOINT");
Important

After you modify the application code, restart the application for the changes to take effect.

Verify the environment variable

Run the following command on the server to confirm that the environment variable is set:

echo $API_ENDPOINT

The command returns the value you defined in ~/.bash_profile.

Notes

  • Variables defined in ~/.bash_profile are loaded each time the admin user starts a login shell.

  • Before you modify configurations or data on an ECS instance or an ApsaraDB RDS instance, create snapshots or enable backup features such as log backup for ApsaraDB RDS.

  • If you submitted sensitive information such as passwords in the Alibaba Cloud Management Console, update the credentials promptly.