All Products
Search
Document Center

Environment stage management

Last Updated: Jan 21, 2019

What is environment management

Currently, all APIs are grouped into three environments: Test, Pre, and Release. The Test and Pre environments are used by testers to test or debug APIs. Users use APIs in the Release Environment.

You can add variable parameters for API groups, defining different environment stages for APIs used in the Test, Pre, and Release environments. An environment variable is a public constant that can be customized in each environment. When calling APIs, you can place environment parameters in the request. API Gateway distinguishes the request environment according to the environment parameter information in your request.

How to configure environment variable parameters

Firstly, create variables for each environment. Then, configure the created environment variables when defining APIs.

Create an environment variable

To distinguish request environments using environment variables, you must add a variable for Test, Pre, and Release environment stages respectively.

Currently, each environment allows you to configure up to 50 environment variables.

  1. Log on to the API Gateway console.

  2. Click API Groups > View Stage.

    Environment stage

  3. Select an environment stage (Release, Pre, or Test) and click Add Variable.

    You must add a variable for each environment stage one by one.

  4. Enter the variable name and value, and click Add.

    • Name: The user-defined variable name. Make sure that the names of the variables corresponding to the three environment stages are the same.

      If you have multiple APIs, we recommend that the variable names indicate the actual functions to facilitate future queries.

    • Value: Variable value.

      If Function Compute is the backend service of the API Gateway, enter the name of the service and function created in Function Compute as values of the variables. You must enter the correct names of the service and function, or else you and the other users cannot call the corresponding API.

      Here, we use Function Compute as an example.

      Assuming that we have a function service and its names in the Test, Pre, and Release environments are TestServiceD, PreServiceD, and ServiceD respectively. When you define variables for the APIs of the Test, Pre, and Release environments respectively, you can name the variable “Service” and enter the corresponding service name as the value.

      Add variable

      You can also enter the function name as the value of the environment stage variable named as “Function” and set the respective variables for the three environments.

Configure environment variables in API definitions

When you define the APIs, add the variable in the Request Path, Input Parameter Definitions, and Define API Backend Service.

Expression method: #Variable Name#. For example: #Service# or #Function#.

When you set Function Compute as API Gateway’s backend service, you can enter the created variables as a service name and function name.

Define API

Call a multi-environment API

After an API is published, you call the API in different environments.

Calls to the production environment

To call Release environment APIs, you are not required to add an environment variable.

Calls to the pre-release environment

To call Pre environment APIs, add the parameter X-Ca-Stage: PRE in the header when calling the API.

Calls to the test environment

To call Test environment APIs, add the parameter X-Ca-Stage: TEST in the header when calling the API.