Updated on 2025-08-19 GMT+08:00

API Gateway (Dedicated) Trigger

This section describes how to create an APIG trigger on the FunctionGraph console to invoke a function using an API.

Overview

Dedicated APIG triggers are used together with APIG to invoke functions over HTTPS or HTTP. You can map specific API operations (such as GET, POST, and PUT) to the corresponding functions using the custom REST APIs and endpoints of APIG. When you send an HTTPS request to an APIG endpoint, APIG automatically triggers the corresponding function.

Notes and Constraints

  • Dedicated APIG triggers cannot be disabled and can only be deleted.
  • The function response for APIG invocation is encapsulated and must contain body(String), statusCode(int), headers(Map), and isBase64Encoded(boolean).
    {
        "isBase64Encoded": true|false,
        "statusCode": httpStatusCode,
        "headers": {"headerName":"headerValue",...},
        "body": "..."
    }

    isBase64Encoded is valued true by default, indicating that the request body transferred to FunctionGraph is encoded using Base64 and must be decoded for processing.

  • The valid payload size of a request body is 4 MB when a dedicated APIG trigger is used.

Prerequisites

Creating an APIG (Dedicated) Trigger

  1. Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. On the Function List page, click Create Function in the upper right corner.
  3. Select Create from scratch, configure the following function information, and retain the default values for other parameters.

    • Function Name: Enter a function name, for example, apig_demo.
    • Enterprise Project: Select default.
    • Agency: Select Use no agency.
    • Runtime: Select Python 3.12.

  4. Click Create Function. The function creation is complete, and the function details page is displayed.
  5. On the Code tab page, copy the following code to the code editing area and click Deploy.

    # -*- coding:utf-8 -*-
    import json
    def handler (event, context):
        body = "<html><title>Functiongraph Demo</title><body><p>Hello, FunctionGraph!</p></body></html>"
        print(body)
        return {
            "statusCode":200,
            "body":body,
            "headers": {
                "Content-Type": "text/html",
            },        
            "isBase64Encoded": False
        }

  6. Choose Configuration > Triggers and click Create Trigger as shown in Figure 1.

    Figure 1 Creating a trigger

  7. Set trigger parameters by referring to Table 2.

    Table 2 Parameters for creating a dedicated APIG trigger

    Parameter

    Description

    Example Value

    Trigger Type

    Select API Gateway (Dedicated).

    API Gateway (Dedicated)

    API Instance

    APIG gateway. If no gateway is available, click Create API Instance.

    apig-fg

    API Name

    Name of a dedicated APIG trigger.

    The name can contain 3 to 64 characters and must start with a letter. Only letters, digits, and underscores (_) are allowed.

    For details about API configuration, see Creating an API.

    API_apig

    API Group

    Select an API group. An API group is a collection of APIs. You can manage APIs by API group.

    If no group is available, click Create API Group.

    APIGroup_test

    Environment

    The environment where the API is published. An API can be called in different environments, such as production, test, and development environments only when the parameter is set to RELEASE.

    If no environment is available, click Create Environment.

    RELEASE

    Security Authentication

    Security authentication mode used by the API.

    Options:

    • App: AppKey and AppSecret authentication. This mode is of high security and is recommended. For details, see App Authentication.
    • App: AppKey and AppSecret authentication. This mode is of high security and is recommended. For details, see App Authentication.
    • None: No authentication. This mode grants access permissions to all users.

    In this example, Security Authentication is set to None. You are advised to enable App or IAM authentication in the production environment.

    None

    Protocol

    Request protocol of the API.

    Options:

    • HTTP: Data is not encrypted during transmission.
    • HTTPS: Data is encrypted during transmission. HTTPS is recommended for transmitting important or sensitive data.
    • HTTP&HTTPS

    HTTPS

    Path

    Enter the API request path.

    It is a part of the API access address and is used to specify resource IDs or hierarchy.

    The path is case-sensitive. It starts with a slash (/) and contains a maximum of 512 characters. Enclose parameters in braces. For example: /a/{b}. Or use a plus sign (+) to match parameters starting with specific characters. For example: /a/{b+}.

    /ttest

    Matching

    Select a matching mode for the API.

    Matching mode of the API. Options:

    • Exact match: The request path must be the same as the defined path.
    • Prefix match: The request path must start with the defined path.

    Prefix match

    Method

    Request method of the API.

    Options: GET, POST, DELETE, PUT, PATCH, HEAD, OPTIONS, and ANY.

    ANY indicates that the API can be called using any request method.

    ANY

    Timeout (ms)

    API backend timeout in milliseconds. Range: 1–60,000.

    5000

  8. Click OK.

Invoking the Function

  1. Copy the API URL of the APIG trigger, as shown in Figure 2, open a browser, and enter the URL in the address box.

    Figure 2 Copying the API URL

  2. View the execution result, as shown in Figure 3.

    Figure 3 Returned result

Viewing the Execution Result

  1. Return to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. Click a function to go to its details page.
  3. Choose Monitoring > Logs to query function running logs.