Invoke commands

The invoke command is used to invoke or trigger online functions.

Command description

You can run the invoke -h or invoke --help command to obtain the help documentation.

Parameter description

ParameterAbbreviationRequired in YAML modeRequired in CLI modeDescription
region-NoYesThe 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-NoYesThe name of the service.
function-name-NoYesThe name of the function.
timeout-NoNoThe client timeout session. [Timeout setting principles] (https://github.com/devsapp/fc/issues/480)
qualifier-NoNoSpecify the version or alias to call
eventeNoNoThe event.
event-filefNoNoThe event file.
event-stdinsNoNoThe file of the event.
invocation-type-NoNoThe invocation type. Valid values: async, sync. Default value: sync.
stateful-async-invocation-id-NoNoThe 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

Examples

  • **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!

Precautions

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:

MethodMethod descriptionExample of input parametersCLI invocation example
httpHTTP trigger events cli fc-event http
cdnCDN trigger events cli fc-event cdn
mnsMNS topic trigger events cli fc-event mns
ossOSS trigger events cli fc-event oss
slsSLS trigger events cli fc-event sls
tablestoreTablestore trigger events 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.

Permissions and policies

  • Policy that contains the highest-level permissions: AliyunFCInvocationAccess or AliyunFCFullAccess

  • 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>"
            }
        ]
    }
    
Edit this page on GitHub Updated at Wed, Sep 21, 2022