title | description | position | category |
---|---|---|---|
Invoke commands |
Invoke commands |
2 |
Call&Debugging |
The invoke
command is used to invoke or trigger online functions.
You can run the invoke -h
or invoke --help
command to obtain the help documentation.
Parameter | Abbreviation | Required in YAML mode | Required in CLI mode | Description |
---|---|---|---|---|
region | - | No | Yes | The region where the service resides. Valid values: cn-hangzhou, cn-beijing, cn-beijing, cn-hangzhou, cn-shanghai, cn-qingdao, cn-zhangjiakou, cn-huhehaote, cn-shenzhen, cn-chengdu, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, and ap-south-1 . |
service-name | - | No | Yes | The name of the service. |
function-name | - | No | Yes | The name of the function. |
timeout | - | No | No | The client timeout session. [Timeout setting principles] (#480) |
qualifier | - | No | No | Specify the version or alias to call |
event | e | No | No | The event. |
event-file | f | No | No | The event file. |
event-stdin | s | No | No | The file of the event. |
invocation-type | - | No | No | The invocation type. Valid values: async, sync . Default value: sync . |
stateful-async-invocation-id | - | No | No | The stateful asynchronous invocation. |
The current command also supports some global parameters (such as
-a/--access
,--debug
, etc.). For details, please refer to Serverless Devs global parameters document
- **If the YAML description file of a resource exists, you can run the
s invoke
command to invoke online functions. - If the YAML description file of a resource does not exist (only CLI mode available), you need to specify the region where the service resides, the service name, and the function name. Example:
s invoke --region cn-hangzhou --service-name fc-deploy-service --function-name http-trigger-py36
Sample command output:
Request url: https://1583208943291465.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/fc-deploy-service/http-trigger-py36/
========= FC invoke Logs begin =========
FC Invoke Start RequestId: 68f15da2-a453-4f7e-90d3-91198b76afbf
FC Invoke End RequestId: 68f15da2-a453-4f7e-90d3-91198b76afbf
Duration: 2.96 ms, Billed Duration: 3 ms, Memory Size: 128 MB, Max Memory Used: 10.83 MB
========= FC invoke Logs end =========
FC Invoke Result[code: ${resp.code}]:
Hello world!
During the function invocation, if you need to specify related events, such as Object Storage Service (OSS) events, Alibaba Cloud CDN (CDN) events, you can use the following command to obtain the event format: s cli fc-event
:
Method | Method description | Example of input parameters | CLI invocation example |
---|---|---|---|
http | HTTP trigger event | s cli fc-event http | |
cdn | CDN trigger event | s cli fc-event cdn | |
mns | MNS topic trigger event | s cli fc-event mns | |
oss | OSS trigger event | s cli fc-event oss | |
sls | SLS trigger event | s cli fc-event sls | |
tablestore | Tablestore trigger event | s cli fc-event tablestore |
The following example uses an OSS event for testing. You can run the s cli fc-event oss
command to obtain the information about the OSS event, and you can find the relative path in the following command output:
...
👓 Event Template Path: event-template/oss-event.json
...
You can use the template of the path to trigger functions. The template can be modified based on your business requirements. Example: s invoke --event-file event-template/oss-event.json
.
-
Policy that contains the highest-level permissions:
AliyunFCInvocationAccess
orAliyunFCFullAccess
-
Policy that contains the lowest-level permissions::
{ "Version": "1", "Statement": [ { "Action": "fc:InvokeFunction", "Effect": "Allow", "Resource": "acs:fc:<region>:<account-id>:services/<serviceName>.<qualifier>/functions/<functionName>" } ] }