To use API Gateway to trigger function execution, you must set Function Compute as the backend service of the API operation and then publish the API operation. This topic describes how to create, debug, and publish API operations in the API Gateway console.

Step 1: Create a group

APIs are managed by group. Before you create an API operation, you must create a group. If you have created an API group, skip this step.

  1. Log on to the API Gateway console.
  2. Select the region where the API operation is located.
    Note If the region where you created the API group is not the region where you created the service in Function Compute, API Gateway accesses the service in Function Compute over the Internet. If you need high data security and low network latency, select the region where you created the service in Function Compute when you create the API group in API Gateway.
  3. Choose Publish APIs > API Groups.
  4. Click Create Group.
  5. Select an instance from the drop-down list of Instance, set Group Name, and then click OK.
    create-group
    The API group you created is displayed in the API group list.create-group-result

Step 2: Create an API operation

  1. In the left-side navigation pane, choose Publish APIs > APIs.
  2. Click Create API.
  3. Enter the required information based on the configuration wizard.
    For more information about the parameters, see Create APIs.
    1. In the Basic Information step, set parameters as needed, and then click Next.
      basic-information
    2. In the Define API Request step, define the API request, and then click Next.
      define-API-resquest
    3. In the Define API Backend Service step, configure a backend service for the API operation, and click Next.
      define-backend-service
      Parameter Description
      Backend Service Type Select FunctionCompute.
      Function Type Select the type of the function in Function Compute that connects to API Gateway. Valid values:
      • Event Function
      • HTTP Function
      Region Select the region of the function in Function Compute that connects to API Gateway.
      Service Name Enter the name of the service where the function in Function Compute that connects to API Gateway is located.
      Function Name Enter the name of the function in Function Compute that connects to API Gateway.
      Function Alias Enter an alias for the function. Default value: LATEST. To enter another alias, make sure that you have created this alias in the Function Compute console. For more information, see Create an alias.
      Role Arn Click Get Authorization. A default role is automatically assigned.
      Backend Timeout Set the timeout period of the backend service.
    4. In the Define Response step, configure response information for the API operation and click Create.
      define-callback
      After the API operation is created, it is listed on the APIs page.create-API-result

Debug the API operation

For more information about how to debug the API operation, see Debug an API operation.

Publish an API operation

  1. On the API List page, find the target API operation.
  2. Click Deploy in the Operation column.
  3. In the Deploy API dialog box, select the environment you want to publish the API operation, enter remarks, and then click Deploy.
    publish api
    After the API operation is published, you can use this API operation of API Gateway to access the function.

References