This topic describes how to obtain custom environment variables from an application.
Solutions
Before you perform high-risk operations, such as modifying the configurations or data of an instance, we recommend that you check the disaster recovery and fault tolerance capabilities of the instance to ensure data security.
Before you modify the configurations or data of an instance, such as an Elastic Compute Service (ECS) instance or an ApsaraDB RDS instance, we recommend that you create snapshots or enable the backup feature for the instance. For example, you can enable the log backup feature for an ApsaraDB RDS instance.
If you have granted permissions on sensitive information or submitted sensitive information in the Alibaba Cloud Management Console, we recommend that you modify the sensitive information at the earliest opportunity. Sensitive information includes usernames and passwords.
Log on to the application server and run the following command to switch to the admin account:
su - admin
Edit the
~/.bash_profile
file to add the custom environment variables that you want to obtain. Then, save the configurations and exit from the code editor.Run the following command to execute the script:
source ~/.bash_profile
After you execute the script, call methods such as
System.getenv()
to obtain the custom environment variables from the application code.ImportantAfter the application code is modified, restart the application to make the configurations take effect.