This topic describes trigger-related commands in the FC-API component.
Prerequisites
- Install Serverless Devs
- Configure Serverless Devs
- Create a service
- Create a function
- Optional:Create buckets
To create an Object Storage Service (OSS) event trigger, you must create a bucket.
Note The OSS bucket and your function must reside in the same region. - Optional:Create a topic
To create a Message Service (MNS) topic trigger, you must create a topic.
- Optional:To create a Tablestore trigger, complete the following operations:
- Optional:To create an Alibaba Cloud CDN trigger, complete the following operations:
Create a trigger
s cli fc-api createTrigger --region <cn-hangzhou> --access <keyname> --props <props> --serviceName <serviceName> --functionName <functionName> --invocationRole <role> --qualifier <version or alias> --triggerName <triggerName> --triggerConfig <triggerconfig> --triggerType <triggertype>
- --region string: the ID of the region where the resource is deployed.
- --access string: the alias of the key used.
- --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
- --serviceName string: the name of the service.
- --functionName string: the name of the function.
- --invocationRole string: the role to be assumed when the trigger is used to invoke the function.
- --qualifier string: the alias or version of the service.
- --sourceArn string: the ARN of the event source for the trigger.
- --triggerConfig string: the configuration of the trigger.
- --triggerName string: the name of the trigger.
- --triggerType string: the type of the trigger. Supported types of triggers include OSS event triggers, Log Service triggers, time triggers, HTTP triggers, Tablestore triggers, CDN event triggers, and MNS topic triggers.
- macOS or Linux operating system
s cli fc-api createTrigger --region cn-hangzhou --serviceName mytest --functionName mytest --triggerName mytrigger --triggerConfig '{"payload": "", "cronExpression": "@every 1m", "enable": true}' --triggerType timer
- Windows operating system
s cli fc-api createTrigger --region cn-hangzhou --serviceName mytest --functionName mytest --triggerName mytrigger --triggerConfig "{\"payload\": \"\", \"cronExpression\": \"@every 1m\", \"enable\": true}" --triggerType timer
For information about the API operation for creating a trigger, see CreateTrigger.
Delete a trigger
s cli fc-api deleteTrigger --region <regionid> --aeecss <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --triggerName <triggerName>
- --region string: the ID of the region where the resource is deployed.
- --access string: the alias of the key used.
- --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
- --serviceName string: the name of the service.
- --functionName string: the name of the function.
- --triggerName string: the name of the trigger.
s cli fc-api deleteTrigger --region cn-hangzhou --serviceName mytest --functionName mytest --triggerName mytrigger
For information about the API operation for deleting a trigger, see DeleteTrigger.
Modify a trigger
s cli fc-api updateTrigger --region <regionid> --serviceName <serviceName> --functionName <functionName> --triggerName <triggerName> --triggerConfig <triggerconfig> --triggerType <triggertype>
- --region string: the ID of the region where the resource is deployed.
- --access string: the alias of the key used.
- --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
- --serviceName string: the name of the service.
- --functionName string: the name of the function.
- --invocationRole string: the role to be assumed when the trigger is used to invoke the function.
- --qualifier string: the alias or version of the service.
- --sourceArn string: the ARN of the event source for the trigger.
- --triggerConfig string: the configuration of the trigger.
- --triggerName string: the name of the trigger.
- --triggerType string: the type of the trigger. Supported types of triggers include OSS event triggers, Log Service triggers, time triggers, HTTP triggers, Tablestore triggers, CDN event triggers, and MNS topic triggers.
- macOS or Linux operating system
s cli fc-api updateTrigger --region cn-hangzhou --serviceName mytest --functionName mytest --triggerName mytrigger --triggerConfig '{"payload": "", "cronExpression": "@every 1m", "enable": true}' --triggerType timer
- Windows operating system
s cli fc-api updateTrigger --region cn-hangzhou --serviceName mytest --functionName mytest --triggerName mytrigger --triggerConfig "{\"payload\": \"\", \"cronExpression\": \"@every 1m\", \"enable\": true}" --triggerType timer
For information about the API operation for modifying a trigger, see UpdateTrigger.
Query the information about a trigger
s cli fc-api getTrigger --region <regionid> --access <accessName> --props <props> --serviceName <serviceName> --functionName <functionName> --triggerName <triggerName>
- --region string: the ID of the region where the resource is deployed.
- --access string: the alias of the key used.
- --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
- --serviceName string: the name of the service.
- --functionName string: the name of the function.
- --triggerName string: the name of the trigger.
s cli fc-api getTrigger --region cn-hangzhou --serviceName mytest --functionName mytest --triggerName mytrigger
For information about the API operation for querying the information about a trigger, see GetTrigger.
Query triggers
s cli fc-api listTriggers --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --limit <limit number> --nextToken <nextresult> --prefix <return prefix> --startkey <startkey>
- --region string: the ID of the region where the resource is deployed.
- --access string: the alias of the key used.
- --props string: the properties of the component. For more information about the props parameter, see YAML syntax.
- --limit string: the maximum number of resources to be returned.
- --nextToken string: the token used to return more results. If the number of resources exceeds the limit, the nextToken parameter is returned. Include this parameter in subsequent calls to obtain more results. You do not need to provide this parameter in the first call.
- --prefix string: the prefix that the names of returned resources must contain.
- --startKey string: the start position of the result list. Results are in alphabetical order, and the results that follow startKey (inclusive) are listed.
- --serviceName string: the name of the service.
- --functionName string: the name of the function.
s cli fc-api listTriggers --serviceName mytest --functionName mytest
For information about the API operation for querying triggers, see ListTriggers.