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}
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
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. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
trigger_type_code |
Yes |
String |
Trigger type.
Enumeration values:
|
trigger_status |
No |
String |
Trigger status. Options: ACTIVE and DISABLED. Enumeration values:
|
event_type_code |
No |
String |
Message code. |
event_data |
Yes |
Object |
Event struct. |
Response Parameters
Status code: 201
Parameter |
Type |
Description |
---|---|---|
trigger_id |
String |
Trigger ID. |
trigger_type_code |
String |
Trigger type.
Enumeration values:
|
trigger_status |
String |
Trigger status.
Enumeration values:
|
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
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Status code: 401
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Status code: 403
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Status code: 404
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Status code: 500
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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot