Help Center/ API Gateway/ User Guide (Paris Region)/ API Opening/ Environment Management/ Creating an Environment and Environment Variable
Updated on 2022-02-21 GMT+08:00

Creating an Environment and Environment Variable

Scenario

An API can be called in different environments, such as production, testing, and development environments. RELEASE is the default environment provided by API Gateway. You can define environment variables to allow an API to be called in different environments.

Environment variables are manageable and specific to environments. You can create variables in different environments to call different backend services using the same API.

For variables you define during API creation, you must create corresponding variables and values. For example, variable Path is defined for an API, and two variables with the same name are created and assigned values /Stage/test and /Stage/AA in environments 1 and 2, respectively. If the API is published and called in environment 1, the path /Stage/test is used. If the API is published and called in environment 2, the path /Stage/AA is used.

Figure 1 Use of environment variables

You can create a maximum of 10 environments and a maximum of 50 variables for an API group in an environment.

Prerequisites

You have created an API group.

Creating an Environment

  1. Log in to the management console.
  2. Click in the upper left corner and choose API Gateway.
  3. In the navigation pane, choose API Publishing > Environments.
  4. Click Create Environment, and set the parameters listed in Table 1.

    Table 1 Environment information

    Parameter

    Description

    Name

    Environment name.

    Description

    Description of the environment.

  5. Click OK.

    After the environment is created, it is displayed in the environment list.

Accessing an Environment

You can call an API in the RELEASE environment by using a RESTful API. To access the API in other environments, add the X-Stage header to the request to specify an environment name. For example, add X-Stage:DEVELOP to the request header to access an API in the DEVELOP environment.

API Gateway does not support API debugging using environment variables.

Creating an Environment Variable

  1. Log in to the management console.
  2. Click in the upper left corner and choose API Gateway.
  3. In the navigation pane, choose API Publishing > API Groups.
  4. Create a variable. You can use one of the following methods:

    • Click the name of the target API group, and click the Variables tab on the displayed API group details page.
    • In the Operation column of the target API group, choose More > Manage Variable.

  5. Select an environment from the Environment drop-down list, and click Create Variable.
  6. Set the parameters listed in Table 2.

    Table 2 Parameters for creating an environment variable

    Parameter

    Description

    Name

    Name of the variable you want to create. Ensure that the name is the same as the name of the variable defined for the API.

    Value

    The path to be used in the selected environment.

  7. Click OK.

    If a variable is not needed, click Delete in the row containing the variable to delete it.

    Environment variable names and values will be displayed in plain text in API requests. Do not include sensitive information in the variable names and values.

Follow-Up Operations

After creating an environment and variable, publish APIs in the environment so that they can be called by API callers.