Updating a Trigger
Function
This API is used to update a trigger.
Calling Method
For details, see Calling APIs.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions. For details about the required permissions, see Permissions Policies and Supported Actions.
URI
PUT /v2/{project_id}/fgs/triggers/{function_urn}/{trigger_type_code}/{trigger_id}
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Parameter description: Project ID. For details, see Obtaining a Project ID. Constraints N/A Value range: 32 characters, including letters and digits. Default value: N/A |
| function_urn | Yes | String | Parameter description: URN of the function. For details, see Function Model. Constraints N/A Value range: Only letters, digits, underscores (_), hyphens (-), and colons (:) are allowed. Default value: N/A |
| trigger_type_code | Yes | String | Definition: Trigger type code. Constraints None Range Default Value None |
| trigger_id | Yes | String | Parameter description: Trigger ID. Constraints None Range: None Default Value None |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | Parameter description: User token. The token can be obtained by calling the IAM API. The value of X-Subject-Token in the response header is the user token. Constraints N/A Value range: N/A Default value: N/A |
| Content-Type | Yes | String | Message body type (format). |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| trigger_status | No | String | Parameter description: Trigger status. The initial status of a trigger can be enabled or disabled. Constraints None Range Default Value DISABLED |
| event_data | No | Array of UpdateriggerEventData objects | Parameter description: Trigger update event. Constraints This field is supported only by DIS triggers. Range: None Default Value None |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| is_serial | No | Boolean | Parameter description: Whether to process data in serial mode. Constraints This field is supported only by DIS triggers. Range true: Data is processed in serial mode. false: Data is processed in parallel mode. |
| max_fetch_bytes | No | Integer | Definition: Maximum number of bytes that can be pulled by a DIS trigger at a time, in bits. Constraints This field is supported only by DIS triggers. Range 0-4 MB(4194304B). Default Value 4 MB |
| polling_interval | No | Integer | Parameter description: Pull interval of a DIS trigger, which is used to specify the interval at which the trigger obtains messages from the DIS stream. The unit is specified by polling_unit. Constraints This parameter and polling_unit can be used only by DIS triggers. Range The value is a positive integer. Default Value None |
| polling_unit | No | String | Parameter description: Pull interval unit of a DIS trigger, which is used together with polling_interval. Constraints This parameter can be used only by DIS triggers and must be used together with polling_interval. Range ms: Messages are pulled every several milliseconds. s: Messages are pulled every several seconds. Default Value None |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| trigger_id | String | Parameter description: Trigger ID. Range: None |
| trigger_type_code | String | Definition: Trigger type code. Range RABBITMQ: RabbitMQ trigger DEDICATEDGATEWAY: dedicated gateway trigger OPENSOURCEKAFKA: open-source Kafka trigger APIC: ROMA Connect trigger GAUSSMONGO: GaussDB(for Mongo) trigger IOTDA: IoTDA trigger ROCKETMQ: RocketMQ trigger DYNAMODB: DynamoDB trigger |
| trigger_status | String | Parameter description: Trigger status. Value range: |
| event_data | TriggerEventDataResponseBody object | Parameter description: Trigger attribute structure. Range: None |
| last_updated_time | String | Parameter description: Last update time. Range Time |
| created_time | String | Parameter description: Time when the trigger was created. Range Time |
| Parameter | Type | Description |
|---|---|---|
| name | String | Parameter description: Specifies the trigger name. Range: None |
| schedule_type | String | Parameter description: Timer trigger type (timer trigger parameter). Range
|
| schedule | String | Parameter description: Triggering rule. (timer trigger parameter). Range When the trigger type is Rate, the scheduled rule is used. When the trigger type is Cron, the Cron expression is used. |
| user_event | String | Parameter description: Additional information (timer trigger parameter). When the Timer trigger triggers function execution, the execution event (event parameter of the function) is as follows: {"version": "v1.0", "time": "2018-06-01T08:30:00+08:00", "trigger_type": "TIMER", "trigger_name": "Timer_001", "user_event": "Additional information you entered." Value range: N/A |
| triggerid | String | Parameter description: APIG trigger ID (APIG trigger parameter). Range: None |
| type | Integer | Parameter description: API type (APIG trigger parameter). Range |
| path | String | Parameter description: Path of the API (APIG trigger parameter). Range The value must comply with the URI naming rules. |
| protocol | String | Parameter description: Request protocol of the API (APIG trigger parameter). Range HTTP: HTTP protocol HTTPS: HTTPS protocol |
| req_method | String | Parameter description: Request mode of the API (APIG trigger parameter). Range GET: triggered by an HTTP GET request POST: triggered by an HTTP POST request PUT: triggered by an HTTP PUT request DELETE: triggered by an HTTP DELETE request HEAD: triggered by an HTTP HEAD request PATCH: triggered by an HTTP PATCH request OPTIONS: triggered by an HTTP OPTIONS request ANY: triggered by any HTTP request |
| group_id | String | Parameter description: ID of the group to which the API belongs (APIG trigger parameter). Range: None |
| group_name | String | Parameter description: Name of the group to which the API belongs (APIG trigger parameter). Range: None |
| match_mode | String | Parameter description: Matching mode of the API (APIG trigger parameter). Range |
| env_name | String | Parameter description: Environment in which the API is published (APIG trigger parameter). Range: None |
| env_id | String | Parameter description: ID of the environment in which the API has been published (APIG trigger parameter). Range: None |
| api_id | String | Parameter description: API ID (APIG trigger parameter). Range: None |
| api_name | String | Parameter description: API name (APIG trigger parameter). Range: None |
| auth | String | Parameter description: Security authentication (APIG trigger parameter). Range IAM: IAM authentication. This mode grants access permissions to IAM users only and is of medium security. APP: AppKey and AppSecret authentication. This mode is of high security and is recommended. NONE: Authentication is not required. All users can access this API. This mode is not recommended. |
| invoke_url | String | Parameter description: API calling address (APIG trigger parameter). Range: None |
| func_info | ApigTriggerFuncInfo object | Parameter description: Function backend information corresponding to the APIG trigger. Range: None |
| sl_domain | String | Parameter description: Subdomain name allocated by the APIG system by default (APIG trigger parameter). Range: None |
| backend_type | String | Parameter description: Backend type of the API (APIG trigger parameter). Range FUNCTION |
| instance_id | String | Parameter description: Instance ID. This parameter is mandatory for DDS, RabbitMQ, and RocketMQ and Kafka triggers. Range APIG trigger: APIG gateway ID. DDS trigger: DDS instance ID. Kafka trigger: Kafka instance ID. RabbitMQ trigger: RabbitMQ instance ID. RocketMQ trigger: RocketMQ instance ID. |
| instance_ip | String | Parameter description: Database IP address (DynamoDB trigger parameter). Range: None |
| table_name | String | Parameter description: Database table name (DynamoDB trigger parameter). Range: None |
| roma_app_id | String | Parameter description: ID of the integration application to which the API belongs (APIG trigger parameter). Range: None |
| operations | Array of strings | Parameter description: Custom operations (CTS trigger parameter). CTS collects operation records of subscribed cloud resources. If you create a function with a CTS trigger, collected operation records of specified cloud services will be passed as a parameter to invoke the function. Range: None |
| collection_name | String | Parameter description: Collection name (DDS trigger parameter). Range: None |
| db_name | String | Parameter description: Database name (DDS trigger parameter). Range: None |
| db_password | String | Parameter description: DDS database password (DDS trigger parameter). Range: None |
| db_user | String | Parameter description: DDS database username (DDS trigger parameter). Range: None |
| instance_addrs | Array of strings | Parameter description: DDS database instance address (DDS trigger parameter). Range: None |
| mode | String | Parameter description: DDS database instance type (DDS trigger parameter). Range Sharding: cluster instance ReplicaSet: replica set instance Single: single node instance |
| batch_size | Integer | Parameter description: Batch size: Maximum number of data records that can be processed by the function at a time. This parameter is mandatory for DIS, DDS, Kafka, RocketMQ, and RabbitMQ triggers. Range DDS trigger: Enter a value from 1 to 10,000. DIS trigger: Enter a value from 1 to 10,000. Kafka trigger: Enter a value from 1 to 1,000. RabbitMQ trigger: Enter a value from 1 to 1,000. RocketMQ trigger: Enter a value from 1 to 1,000. |
| queue_id | String | Parameter description: Queue ID (DMS trigger parameter). Range: None |
| consumer_group_id | String | Parameter description: Consumer group ID (DMS trigger parameter). Range: None |
| polling_interval | Integer | Parameter description: Pull period. Range: None |
| stream_name | String | Parameter description: Stream name (DIS trigger parameter). Range: None |
| sharditerator_type | String | Parameter description: Starting position (DIS/DynamoDB trigger parameter). Range |
| polling_unit | String | Parameter description: Pull period unit (DIS trigger parameter). Range ms: millisecond |
| max_fetch_bytes | Integer | Parameter description: Max. fetch bytes (DIS trigger parameter). Range: None |
| is_serial | String | Parameter description: Whether to process data in serial mode (DIS trigger parameter). Range |
| log_group_id | String | Parameter description: Log group ID (LTS trigger parameter). Range: None |
| log_topic_id | String | Parameter description: Log stream ID (LTS trigger parameter). Range: None |
| bucket | String | Parameter description: Bucket name (OBS trigger parameter). The name of the OBS bucket used as the event source cannot be the same as that of an existing bucket of the current user or another user. After being created, the bucket name cannot be modified. Range: None |
| prefix | String | Parameter description: Prefix (OBS trigger parameter). Enter a prefix to limit notifications to objects whose names start with the matching characters. Range: None |
| suffix | String | Parameter description: Suffix (OBS trigger parameter). Enter a suffix to limit notifications to objects whose names end with the matching characters. Range: None |
| events | Array of strings | Parameter description: Trigger event (OBS trigger parameter). Range ObjectCreated: all kinds of object creation operations, including PUT, POST, COPY, and part assembling Put: object upload using PUT Post: object upload using POST Copy: object copying using COPY CompleteMultipartUpload: Assemble parts in a multipart upload. ObjectRemoved: deleting objects Delete: object deletion with a version ID specified DeleteMarkerCreated: object deletion with no version ID specified |
| topic_urn | String | Parameter description: Topic URN (SMN trigger parameter) Range: None |
| topic_ids | Array of strings | Parameter description: The Kafka topic ID list (Kafka trigger parameter). Range: None |
| kafka_user | String | Parameter description: Kafka account name (Kafka trigger parameter). Range: None |
| kafka_password | String | Parameter description: Kafka password (Kafka trigger parameter). Range: None |
| kafka_connect_address | String | Parameter description: Kafka instance connection address (Kafka trigger parameter). Range: None |
| kafka_ssl_enable | Boolean | Parameter description: Whether to enable security authentication (Kafka trigger parameter). Range: None |
| access_password | String | Parameter description: RabbitMQ account password (RabbitMQ trigger parameter). Range: None |
| access_user | String | Parameter description: RabbitMQ username (RabbitMQ trigger parameter). Range: None |
| connect_address | String | Parameter description: Instance IP address (RabbitMQ trigger parameter). Range: None |
| exchange_name | String | Parameter description: Switch name (RabbitMQ trigger parameter). Range: None |
| vhost | String | Parameter description: Virtual host (RabbitMQ trigger parameter). Range: None |
| ssl_enable | Boolean | Parameter description: Whether to enable security authentication (RabbitMQ trigger parameter). Range |
| enable_acl | Boolean | Parameter description: Whether to enable username and password authentication (RocketMQ trigger parameter). Range false: no |
| access_key | String | Parameter description: Connection username (RocketMQ trigger parameter). This parameter is mandatory when enable_acl is set to true. Range: None |
| secret_key | String | Parameter description: Connection password (RocketMQ trigger parameter). This parameter is mandatory when enable_acl is set to true. Range: None |
| Parameter | Type | Description |
|---|---|---|
| function_urn | String | Parameter description: Function URN. For details, see the function model descriptions. Range: None |
| invocation_type | String | Parameter description: Execution mode of a function. Range sync: synchronous execution async: asynchronous execution |
| timeout | Integer | Parameter description: Timeout allowed for APIG to request the FunctionGraph service. The unit is in millisecond. This parameter is mandatory for APIG triggers. Range 1 to 60000 seconds |
| version | String | Parameter description: Function version information. Range: None |
Status code: 404
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Error code. |
| error_msg | String | Error message. |
Example Requests
Enable a trigger.
PUT https://{Endpoint}/v2/{project_id}/fgs/triggers/{function_urn}/{trigger_type_code}/{trigger_id}
{
"trigger_status" : "ACTIVE"
} Example Responses
Status code: 200
{
"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" : "2019-10-29 17:15:53"
} Status code: 404
{
"error_code" : "FSS.0404",
"error_msg" : "not found"
} SDK Sample Code
The SDK sample code is as follows.
Java
Enable a trigger.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.functiongraph.v2.region.FunctionGraphRegion; import com.huaweicloud.sdk.functiongraph.v2.*; import com.huaweicloud.sdk.functiongraph.v2.model.*; public class UpdateTriggerSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); FunctionGraphClient client = FunctionGraphClient.newBuilder() .withCredential(auth) .withRegion(FunctionGraphRegion.valueOf("<YOUR REGION>")) .build(); UpdateTriggerRequest request = new UpdateTriggerRequest(); request.withFunctionUrn("{function_urn}"); request.withTriggerTypeCode(UpdateTriggerRequest.TriggerTypeCodeEnum.fromValue("{trigger_type_code}")); request.withTriggerId("{trigger_id}"); UpdateTriggerRequestBody body = new UpdateTriggerRequestBody(); body.withTriggerStatus(UpdateTriggerRequestBody.UpdateTriggerRequestBody.fromValue("ACTIVE")); request.withBody(body); try { UpdateTriggerResponse response = client.updateTrigger(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Python
Enable a trigger.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkfunctiongraph.v2.region.functiongraph_region import FunctionGraphRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkfunctiongraph.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = FunctionGraphClient.new_builder() \ .with_credentials(credentials) \ .with_region(FunctionGraphRegion.value_of("<YOUR REGION>")) \ .build() try: request = UpdateTriggerRequest() request.function_urn = "{function_urn}" request.trigger_type_code = "{trigger_type_code}" request.trigger_id = "{trigger_id}" request.body = UpdateTriggerRequestBody( trigger_status="ACTIVE" ) response = client.update_trigger(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
Enable a trigger.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" functiongraph "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth, err := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). SafeBuild() if err != nil { fmt.Println(err) return } hcClient, err := functiongraph.FunctionGraphClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). SafeBuild() if err != nil { fmt.Println(err) return } client := functiongraph.NewFunctionGraphClient(hcClient) request := &model.UpdateTriggerRequest{} request.FunctionUrn = "{function_urn}" request.TriggerTypeCode = model.GetUpdateTriggerRequestTriggerTypeCodeEnum().TRIGGER_TYPE_CODE request.TriggerId = "{trigger_id}" triggerStatusUpdateTriggerRequestBody:= model.GetUpdateTriggerRequestBodyTriggerStatusEnum().ACTIVE request.Body = &model.UpdateTriggerRequestBody{ TriggerStatus: &triggerStatusUpdateTriggerRequestBody, } response, err := client.UpdateTrigger(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
More
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
| Status Code | Description |
|---|---|
| 200 | OK |
| 404 | Not Found |
Error Codes
See Error Codes.
What is your overall rating for this page?
Thank 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