Updated on 2023-07-06 GMT+08:00

Creating a Trigger

Function

This API is used to create a trigger.

  • Trigger types include timer, APIG, CTS, DDS, DMS, DIS, LTS, OBS, SMN, and Kafka.

  • By default, DDS and Kafka triggers are in the DISABLED state, and other triggers are in the ACTIVE state.

    • Only timer, DDS, DMS, Kafka, and LTS triggers can be disabled.

URI

POST /v2/{project_id}/fgs/triggers/{function_urn}

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details, see Obtaining a Project ID.

function_urn

Yes

String

Function URN. For details, see the function model description.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

trigger_type_code

Yes

String

Trigger type.

  • TIMER

  • APIG

  • CTS: Enable CTS first.

  • DDS: Configure a VPC for the function first.

  • DMS: Configure a DMS agency first.

  • DIS: Configure a DIS agency first.

  • LTS: Configure an LTS agency first.

  • OBS

  • KAFKA

Enumeration values:

  • TIMER

  • APIG

  • CTS

  • DDS

  • DMS

  • DIS

  • LTS

  • OBS

  • SMN

  • KAFKA

  • RABBITMQ

  • DEDICATEDGATEWAY

  • OPENSOURCEKAFKA

  • APIC

  • GAUSSMONGO

  • EVENTGRID

  • IOTDA

trigger_status

No

String

Trigger status. Options: ACTIVE and DISABLED.

Enumeration values:

  • ACTIVE

  • DISABLED

event_type_code

No

String

Message code.

event_data

Yes

Object

Event struct.

Response Parameters

Status code: 201

Table 4 Response body parameters

Parameter

Type

Description

trigger_id

String

Trigger ID.

trigger_type_code

String

Trigger type.

  • TIMER

  • APIG

  • CTS

  • DDS

  • DMS

  • DIS

  • LTS

  • OBS

  • SMN

  • KAFKA

Enumeration values:

  • TIMER

  • APIG

  • CTS

  • DDS

  • DMS

  • DIS

  • LTS

  • OBS

  • SMN

  • KAFKA

  • RABBITMQ

  • DEDICATEDGATEWAY

  • OPENSOURCEKAFKA

  • APIC

  • GAUSSMONGO

  • EVENTGRID

  • IOTDA

trigger_status

String

Trigger status.

  • ACTIVE: The trigger is enabled.

  • DISABLED: The trigger is disabled.

Enumeration values:

  • ACTIVE

  • DISABLED

event_data

Object

Trigger source event.

last_updated_time

String

Latest update time.

created_time

String

Time when the trigger was created.

Status code: 400

Table 5 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 401

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 403

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 404

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

  • Create an OBS trigger.

    POST https://{Endpoint}/v2/{project_id}/fgs/triggers/{function_urn}
    
    {
      "trigger_type_code" : "OBS",
      "trigger_status" : "ACTIVE",
      "event_data" : {
        "bucket" : "input-picture2",
        "events" : [ "s3:ObjectCreated:*" ],
        "name" : "obs-event-1ec7"
      }
    }
  • Create an APIG trigger.

    POST https://{Endpoint}/v2/{project_id}/fgs/triggers/{function_urn}
    
    {
      "trigger_type_code" : "APIG",
      "trigger_status" : "ACTIVE",
      "event_data" : {
        "func_info" : {
          "timeout" : 5000
        },
        "name" : "API_test_gxz_v1_billing",
        "env_id" : "DEFAULT_ENVIRONMENT_RELEASE_ID",
        "env_name" : "RELEASE",
        "protocol" : "HTTPS",
        "auth" : "NONE",
        "group_id" : "318b09eb214a41488c667ecd51667e3x",
        "sl_domain" : "318b09eb214a41488c667ecd51667e3x.apig.{region}.huaweicloudapis.com",
        "match_mode" : "SWA",
        "req_method" : "ANY",
        "backend_type" : "FUNCTION",
        "type" : 1,
        "path" : "/test_gxz_v1_billing"
      }
    }
  • Create a Kafka trigger.

    POST https://{Endpoint}/v2/{project_id}/fgs/triggers/{function_urn}
    
    {
      "trigger_type_code" : "KAFKA",
      "trigger_status" : "DISABLED",
      "event_data" : {
        "instance_id" : "86ad3efc-c019-460e-91e7-317b1a89f95x",
        "topic_ids" : [ "PUSH_TOKEN_RECORD" ],
        "batch_size" : 100
      }
    }
  • Create a timer trigger.

    POST https://{Endpoint}/v2/{project_id}/fgs/triggers/{function_urn}
    
    {
      "trigger_type_code" : "TIMER",
      "trigger_status" : "ACTIVE",
      "event_data" : {
        "name" : "Timer-l8v2",
        "schedule" : "3m",
        "schedule_type" : "Rate"
      }
    }
  • Create an LTS trigger. (An agency with LTS permissions is required.)

    POST https://{Endpoint}/v2/{project_id}/fgs/triggers/{function_urn}
    
    {
      "trigger_type_code" : "LTS",
      "trigger_status" : "ACTIVE",
      "event_data" : {
        "log_group_id" : "ccd3fa30-7c86-4590-8a9d-XXX",
        "log_group_name" : "function_flow_lts_group_XXX",
        "log_topic_id" : "5b4944dd-9603-481d-9b91-XXX",
        "log_topic_name" : "79eebdc0-3a0d-4231-b88e-XXX"
      }
    }
  • Create an SMN trigger.

    POST https://{Endpoint}/v2/{project_id}/fgs/triggers/{function_urn}
    
    {
      "trigger_type_code" : "SMN",
      "trigger_status" : "ACTIVE",
      "event_data" : {
        "topic_urn" : "urn:smn:{region}:{project_id}:Failed_times"
      }
    }

Example Responses

Status code: 201

Created

{
  "trigger_id" : "9a14fae1-78cf-4185-ac7a-429eb6dc41fb",
  "trigger_type_code" : "TIMER",
  "trigger_status" : "ACTIVE",
  "event_data" : {
    "name" : "Timer-cpg3",
    "schedule" : "3m",
    "schedule_type" : "Rate"
  },
  "last_updated_time" : "2022-11-09 16:37:24",
  "created_time" : "2022-11-09 16:37:24"
}

Status Codes

Status Code

Description

201

Created

400

Bad request.

401

Unauthorized.

403

Forbidden.

404

Not found.

500

Internal server error.

Error Codes

See Error Codes.