Trigger-related commands

更新时间:
复制 MD 格式

Use the FC component — a Serverless Devs-based tool — to manage Function Compute triggers from the command line. All commands follow the same pattern: s cli fc api <Operation>.

Prerequisites

Before you begin, ensure that you have:

Create a trigger

Syntax

sudo s cli fc api CreateTrigger \
  --region <region-id> \
  [--access <access-alias>] \
  [--apiVersion <20210416|20160815>] \
  --path '{"serviceName": "<service-name>", "functionName": "<function-name>"}' \
  --body '{
    "triggerName": "<trigger-name>",
    "triggerType": "<trigger-type>",
    "triggerConfig": <trigger-config>,
    "invocationRole": "<role-arn>",
    "sourceArn": "<source-arn>",
    "qualifier": "<version-or-alias>"
  }'

Parameters

ParameterRequiredDescription
--regionYesRegion where your resources are deployed
--access, -aNoAlias of the access key to use
--apiVersionNoAPI version. Valid values: 20210416, 20160815
--serviceName (in --path)YesName of the service
--functionName (in --path)YesName of the function
--triggerName (in --body)YesName of the trigger
--triggerType (in --body)YesTrigger type. Supported types: OSS event triggers, Simple Log Service triggers, time triggers, HTTP triggers, Tablestore triggers, CDN event triggers, and MNS topic triggers
--triggerConfig (in --body)YesTrigger configuration in JSON format
--invocationRole (in --body)YesThe role that is required by the trigger to invoke the function
--sourceArn (in --body)YesARN of the event source
--qualifier (in --body)NoService version or alias to target

Example: create a timer trigger that fires every minute

macOS or Linux:

sudo s cli fc api CreateTrigger \
  --region cn-hangzhou \
  --access default \
  --path '{"serviceName": "mytest", "functionName": "mytest"}' \
  --body '{"triggerName": "mytrigger", "triggerConfig": {"payload": "", "cronExpression": "@every 1m", "enable": true}, "triggerType": "timer"}'

Windows:

s cli fc api CreateTrigger \
  --region cn-hangzhou \
  --access default \
  --path '{"serviceName": "mytest", "functionName": "mytest"}' \
  --body '{"triggerName": "mytrigger", "triggerConfig": {\"payload\": \"\", \"cronExpression\": \"@every 1m\", \"enable\": true}, "triggerType": "timer"}'

For details about the underlying API operation, see CreateTrigger.

Delete a trigger

Syntax

sudo s cli fc api DeleteTrigger \
  --region <region-id> \
  [--access <access-alias>] \
  [--apiVersion <20210416|20160815>] \
  --path '{"serviceName": "<service-name>", "functionName": "<function-name>", "triggerName": "<trigger-name>"}' \
  [--header '{"If-Match": "<etag>"}']

Parameters

ParameterRequiredDescription
--regionYesRegion where your resources are deployed
--access, -aNoAlias of the access key to use
--apiVersionNoAPI version. Valid values: 20210416, 20160815
--serviceName (in --path)YesName of the service
--functionName (in --path)YesName of the function
--triggerName (in --path)YesName of the trigger to delete
--If-Match (in --header)NoEnsures that the changed resource is the resource that you want to change

Example

sudo s cli fc api DeleteTrigger \
  --region cn-hangzhou \
  --access default \
  --path '{"serviceName": "mytest", "functionName": "mytest", "triggerName": "mytrigger"}'

For details about the underlying API operation, see DeleteTrigger.

Update a trigger

Syntax

sudo s cli fc api UpdateTrigger \
  --region <region-id> \
  [--access <access-alias>] \
  [--apiVersion <20210416|20160815>] \
  --path '{"serviceName": "<service-name>", "functionName": "<function-name>", "triggerName": "<trigger-name>"}' \
  --body '{
    "invocationRole": "<role-arn>",
    "qualifier": "<version-or-alias>",
    "triggerConfig": <trigger-config>
  }' \
  [--header '{"If-Match": "<etag>"}']

Parameters

ParameterRequiredDescription
--regionYesRegion where your resources are deployed
--access, -aNoAlias of the access key to use
--apiVersionNoAPI version. Valid values: 20210416, 20160815
--serviceName (in --path)YesName of the service
--functionName (in --path)YesName of the function
--triggerName (in --path)YesName of the trigger to update
--invocationRole (in --body)YesThe role that is required by the trigger to invoke the function
--qualifier (in --body)YesService version or alias to target
--triggerConfig (in --body)YesUpdated trigger configuration in JSON format
--If-Match (in --header)NoEnsures that the changed resource is the resource that you want to change

Example: disable a timer trigger

macOS or Linux:

sudo s cli fc api UpdateTrigger \
  --region cn-hangzhou \
  --access default \
  --path '{"serviceName": "mytest", "functionName": "mytest", "triggerName": "mytrigger"}' \
  --body '{"triggerConfig": {"payload": "", "cronExpression": "@every 1m", "enable": false}}'

Windows:

s cli fc api UpdateTrigger \
  --region cn-hangzhou \
  --access default \
  --path '{"serviceName": "mytest", "functionName": "mytest", "triggerName": "mytrigger"}' \
  --body '{"triggerConfig": {\"payload\": \"\", \"cronExpression\": \"@every 1m\", \"enable\": false}}'

For details about the underlying API operation, see UpdateTrigger.

Get trigger configuration

Syntax

sudo s cli fc api GetTrigger \
  --region <region-id> \
  [--access <access-alias>] \
  [--apiVersion <20210416|20160815>] \
  --path '{"serviceName": "<service-name>", "functionName": "<function-name>", "triggerName": "<trigger-name>"}'

Parameters

ParameterRequiredDescription
--regionYesRegion where your resources are deployed
--access, -aNoAlias of the access key to use
--apiVersionNoAPI version. Valid values: 20210416, 20160815
--serviceName (in --path)YesName of the service
--functionName (in --path)YesName of the function
--triggerName (in --path)YesName of the trigger

Example

sudo s cli fc api GetTrigger \
  --region cn-hangzhou \
  --access default \
  --path '{"serviceName": "mytest", "functionName": "mytest", "triggerName": "mytrigger"}'

For details about the underlying API operation, see GetTrigger.

List triggers

Syntax

sudo s cli fc api ListTriggers \
  --region <region-id> \
  [--access <access-alias>] \
  [--apiVersion <20210416|20160815>] \
  --path '{"serviceName": "<service-name>", "functionName": "<function-name>"}' \
  [--query '{"limit": "<count>", "nextToken": "<token>", "prefix": "<name-prefix>", "startKey": "<start-key>"}']

Parameters

ParameterRequiredDescription
--regionYesRegion where your resources are deployed
--access, -aNoAlias of the access key to use
--apiVersionNoAPI version. Valid values: 20210416, 20160815
--serviceName (in --path)YesName of the service
--functionName (in --path)YesName of the function
--limit (in --query)NoMaximum number of triggers to return
--nextToken (in --query)NoPagination token from a previous response. Omit this parameter in the first request
--prefix (in --query)NoFilter results to triggers whose names start with this prefix
--startKey (in --query)NoReturn results starting from this key, inclusive, in alphabetical order

Example

sudo s cli fc api ListTriggers \
  --region cn-hangzhou \
  --access default \
  --path '{"serviceName": "mytest", "functionName": "mytest"}'

For details about the underlying API operation, see ListTriggers.