All Products
Search
Document Center

Serverless App Engine:Configure environment variables

Last Updated:Sep 03, 2024

You must configure environment variables to run an application in the system. For example, the commands of a Java application can be run only after the Java_home and Path environment variables are configured. This topic describes how to set environment variables, including custom environment variables and the environment variables that are imported from namespace configuration items, for an application in the SAE console.

Procedure

Configure environment variables during application creation

  1. Log on to the SAE console.

  2. In the left-side navigation pane, click Applications. In the top navigation bar, select a region. Then, click Create Application.

  3. In the Basic Information step, configure the parameters and click Next: Application Deployment Configurations.

  4. In the Deployment Configurations step, configure the Technology Stack Programming Language and Application Deployment Method parameters and the corresponding settings.

  5. In the Environment Variable Settings section, add environment variables as needed.
    • Add a custom environment variable: Select Custom from the Type drop-down list and specify the Variable Name and Variable Value /Variable Reference parameters. sc_environment_variable_option_custom
    • Use a configuration item as an environment variable: Select Reference ConfigMap from the Type drop-down list and specify the Variable Name parameter. Select the name of an existing configuration item and the key in the configuration item from the Variable Value/Variable Reference drop-down lists. You can specify a single key or All Keys. sc_environment_variable_option_use_k8s_configmap

      If you set the Type parameter to Reference ConfigMap, you can create a configuration item on the Namespaces page in advance. Alternatively, you can click Create ConfigMap (K8s configmap) in the Environment Variable Settings section and create a configuration item in the Create ConfigMap panel that appears. For more information, see Manage a Kubernetes ConfigMap.

      If you specify All Keys in the Variable Value/Variable Reference drop-down list, the variable name of each key is the same as the variable name of the selected configuration item by default and cannot be changed.

    Note We recommend that you set a variable name of no more than 256 characters in length. SAE stores environment variables as application deployment properties. You can configure multiple environment variables based on your business requirements.
  6. Optional: To add environment variables, click + Add and repeat the operations in Step5.
  7. Click Next: Confirm Specifications.

  8. In the Specification Confirmation step, view the details of the application and the fee for the selected specifications. Then, click Confirm.

    The Creation Completed step appears. You can click Application Details to go to the Basic Information page of the application.

Configure environment variables during application deployment

Warning

After you redeploy an application, the application is restarted. To prevent unpredictable errors such as business interruptions, we recommend that you deploy applications during off-peak hours.

The procedure that can be performed to update an application varies based on the number of instances in the application. This section provides an example on how to configure the required features for an application in which the number of instances is greater than or equal to 1. For information about how to update an application in which the number of instances is 0, see Update an application.

  1. Log on to the SAE console.

  2. In the left-side navigation pane, click Applications. In the top navigation bar, select a region. Then, click the name of an application.

  3. In the upper-right corner of the Basic Information page, click Deploy Application.

  4. In the Environment Variable Settings section, add environment variables as needed.
    • Add a custom environment variable: Select Custom from the Type drop-down list and specify the Variable Name and Variable Value /Variable Reference parameters. sc_environment_variable_option_custom
    • Use a configuration item as an environment variable: Select Reference ConfigMap from the Type drop-down list and specify the Variable Name parameter. Select the name of an existing configuration item and the key in the configuration item from the Variable Value/Variable Reference drop-down lists. You can specify a single key or All Keys. sc_environment_variable_option_use_k8s_configmap

      If you set the Type parameter to Reference ConfigMap, you can create a configuration item on the Namespaces page in advance. Alternatively, you can click Create ConfigMap (K8s configmap) in the Environment Variable Settings section and create a configuration item in the Create ConfigMap panel that appears. For more information, see Manage a Kubernetes ConfigMap.

      If you specify All Keys in the Variable Value/Variable Reference drop-down list, the variable name of each key is the same as the variable name of the selected configuration item by default and cannot be changed.

    Note We recommend that you set a variable name of no more than 256 characters in length. SAE stores environment variables as application deployment properties. You can configure multiple environment variables based on your business requirements.
  5. After you configure the settings, click Confirm.

Example

MySQL is integrated into an application, and you must configure the environment variables that are required to run MySQL for the application. Configure the following environment variables when you deploy the application in the SAE console:
  • Required:MYSQL_ROOT_PASSWORD: Allows you to set a MySQL root password. If you do not set this parameter, the MySQL container cannot be started.
  • Optional: MYSQL_USER and MYSQL_PASSWORD: Allows you to create an account in addition to the root account and set a password.
  • Optional: MYSQL_DATABASE: Allows you to specify the database that you want to create when the container is generated.