本文介绍FC-API组件中函数的相关命令。

前提条件

创建函数

命令格式:
s cli fc-api createFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --description <description> --code <codefile> --customContainerConfig <customContainerConfig>  --handler <functionhandler> --runtime <runtime> --initializationTimeout <initializationTimeout> --initializer ----memorySize <momorysize> ----timeout <timeout> --caPort <caport>
参数说明:
  • --region string:指定部署资源的地域。
  • --access string:指定使用的密钥别名。
  • --props string:配置组件参数。关于props的参数信息,请参见YAML规范
  • --serviceName string:指定服务名称。
  • --functionName string:指定函数名称。
  • --code string:指定压缩的代码文件,代码文件必须是ZIP格式。
  • --customContainerConfig string:配置Custom Container运行时的参数。配置后函数可以使用自定义容器镜像执行函数。
  • --description string:指定函数中的描述信息。
  • --handler string:设置函数handler,handler的格式为“文件名.函数名”。例如hello_world.handler指定了函数的调用入口为hello_world.js文件中的handler函数。
  • --initializationTimeout number:设置初始化函数超时时间。
  • --initializer string:设置初始化函数。
  • --memorySize number:设置函数执行的内存大小。
  • --runtime string:指定运行环境。
  • --timeout number:设置函数执行的超时时间(默认60s)。
  • --caPort number:指定Custom Runtime或Custom Container运行时HTTP Server的监听端口。
执行示例:
  • macOS操作系统或Linux操作系统,根据运行环境的不同选择执行示例:
    • 当您的运行环境是编程语言运行时,请执行以下命令创建函数:
      s cli fc-api createFunction --serviceName mytest --functionName mytest --code '{"zipFile": "./"}' --handler index.handler --runtime python3
    • 当您的运行环境是自定义容器时,请执行以下命令创建函数:
      s cli fc-api createFunction --serviceName mytest --functionName mytest --customContainerConfig '{"image": "registry-vpc.cn-shenzhen.aliyuncs.com/fc-demo/flask:v0.1"}' --handler index.handler --runtime custom-container
  • Windows操作系统
    • 当您的运行环境是编程语言运行时,请执行以下命令创建函数:
      s cli fc-api createFunction --serviceName mytest --functionName mytest --code "{\"zipFile\": \"./\"}" --handler index.handler --runtime python3
    • 当您的运行环境是自定义容器时,请执行以下命令创建函数:
      s cli fc-api createFunction --serviceName mytest --functionName mytest --customContainerConfig "{\"image\": \"registry-vpc.cn-shenzhen.aliyuncs.com/fc-demo/flask:v0.1\"}" --handler index.handler --runtime custom-container

关于创建函数的API接口的详细信息,请参见CreateFunction

删除函数

命令格式:
s cli fc-api deleteFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName>
参数说明:
  • --region string:指定部署资源的地域。
  • --access string:指定使用的密钥别名。
  • --props string:配置组件参数。关于props的参数信息,请参见YAML规范
  • --serviceName string:指定服务名称。
  • --functionName string:指定函数名称。
执行示例:
s cli fc-api deleteFunction --region cn-hangzhou --access default --serviceName mytest --functionName mytest

关于删除函数的API接口的详细信息,请参见DeleteFunction

更新函数

命令格式:
s cli fc-api updateFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --description <description> --code <codefile> --customContainerConfig <customContainerConfig>  --handler <functionhandler> --runtime <runtime> --initializationTimeout <initializationTimeout> --initializer ----memorySize <momorysize> ----timeout <timeout> --caPort <caport>
参数说明:
  • --region string:指定部署资源的地域。
  • --access string:指定使用的密钥别名。
  • --props string:配置组件参数。关于props的参数信息,请参见YAML规范
  • --serviceName string:指定服务名称。
  • --functionName string:指定函数名称。
  • --code string:指定压缩的代码文件,代码文件必须是ZIP格式。
  • --customContainerConfig string:配置Custom Container运行时的参数。配置后函数可以使用自定义容器镜像执行函数。
  • --description string:指定函数中的描述信息。
  • --handler string:设置函数handler,handler的格式为“文件名.函数名”。例如hello_world.handler指定了函数的调用入口为hello_world.js文件中的handler函数。
  • --initializationTimeout number:设置初始化函数超时时间。
  • --initializer string:设置初始化函数。
  • --memorySize number:设置函数执行的内存大小。
  • --runtime string:指定运行环境。
  • --timeout number:设置函数执行的超时时间(默认60s)。
  • --caPort number:指定Custom Runtime或Custom Container运行时HTTP Server的监听端口。
执行示例:
  • macOS操作系统或Linux操作系统
    • 当您的运行环境是编程语言运行时,请执行以下命令更新函数:
      s cli fc-api updateFunction --serviceName mytest --functionName mytest --code '{"zipFile": "./"}' --timeout 31
    • 当您的运行环境是自定义容器时,请执行以下命令更新函数:
      s cli fc-api updateFunction --serviceName mytest --functionName mytest --code '{"zipFile": "./"}' --timeout 31 --customContainerConfig '{"image": "registry-vpc.cn-shenzhen.aliyuncs.com/fc-demo/flask:v0.1"}'
  • Windows操作系统
    • 当您的运行环境是编程语言运行时,请执行以下命令更新函数:
      s cli fc-api updateFunction --serviceName mytest --functionName mytest --code "{\"zipFile\": \"./\"}" --timeout 31
    • 当您的运行环境是自定义容器时,请执行以下命令更新函数:
      s cli fc-api updateFunction --serviceName mytest --functionName mytest --code "{\"zipFile\": \"./\"}" --timeout 31 --customContainerConfig "{\"image\": \"registry-vpc.cn-shenzhen.aliyuncs.com/fc-demo/flask:v0.1\"}"

关于更新函数的API接口的详细信息,请参见UpdateFunction

获取函数配置信息

命令格式:
s cli fc-api getFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --qualifier <version or alias>
参数说明:
  • --region string:指定部署资源的地域。
  • --access string:指定使用的密钥别名。
  • --props string:配置组件参数。关于props的参数信息,请参见YAML规范
  • --serviceName string:指定服务名称。
  • --functionName string:指定函数名称。
  • --qualifier string:指定服务的别名或版本。
执行示例:
s cli fc-api getFunction --serviceName mytest --functionName mytest --qualifier LATEST

关于获取函数配置信息的API接口的详细信息,请参见GetFunction

获取函数代码信息

命令格式:
s cli fc-api getFunctionCode --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --qualifier <version or alias>
参数说明:
  • --region string:指定部署资源的地域。
  • --access string:指定使用的密钥别名。
  • --props string:配置组件参数。关于props的参数信息,请参见YAML规范
  • --serviceName string:指定服务名称。
  • --functionName string:指定函数名称。
  • --qualifier string:指定服务的别名或版本。
执行示例:
s cli fc-api getFunctionCode --region cn-hangzhou --serviceName mytest --functionName mytest --qualifier LATEST

关于获取函数代码信息的API接口的详细信息,请参见GetFunctionCode

查询函数列表

命令格式:
s cli fc-api listFunctions --region <regionid> --access <accessname> --props <props> --serviceName mytest --qualifier <version or alias> --limit <limit number> --nextToken <nextresult> --prefix <return prefix> --startkey <startkey>
参数说明:
  • --region string:指定部署资源的地域。
  • --access string:指定使用的密钥别名。
  • --props string:配置组件参数。关于props的参数信息,请参见YAML规范
  • --limit string:设置限定此次返回资源的数量。
  • --nextToken string:设置用来返回更多结果的令牌。第一次查询时不需要提供这个参数,后续查询的Token从返回结果中获取。
  • --prefix string:设置返回资源的名称前缀。
  • --startKey string:设定结果从startKey之后(包括startKey)按字母排序的第一个开始返回。
  • --serviceName string:指定服务名称。
  • --qualifier string:指定服务的别名或版本。
执行示例:
s cli fc-api listFunctions --serviceName mytest --qualifier LATEST

关于获取函数列表的API接口的详细信息,请参见ListFunctions

调用执行函数

命令格式:
s cli fc-api invokeFunction --region <regionid> --access <accessname> --props <props> --serviceName <serviceName> --functionName <functionName> --event <event>
参数说明:
  • --region string:指定部署资源的地域。
  • --access string:指定使用的密钥别名。
  • --props string:配置组件参数。关于props的参数信息,请参见YAML规范
  • --serviceName string:指定服务名称。
  • --functionName string:指定函数名称。
  • --event string:设置触发函数执行的事件。
执行示例:
s cli fc-api invokeFunction --region cn-hangzhou --serviceName mytest --functionName mytest

关于调用执行函数的API接口的详细信息,请参见InvokeFunction