Cli 纯命令行模式
cli
命令是去Yaml化的命令行模式,即可以通过命令行直接使用 Serverless Devs 的组件,而不需要依赖Yaml文件。
Yaml 模式与 Cli 模式的区别和试用场景,可以参考文档Yaml 模式 Cli 模式对比
命令解析
当我们执行s cli -h
之后,可以进行相关帮助信息的查看
使用方法主要是:
s cli [组件名称,例如fc,fc3 等] [组件的方法] -p/--props [该方法对应的Yaml属性(JSON字符串)] -a/--access [指定密钥信息] [其他设定]
常见模式
通用组件的支持
在cli
模式下,可以通过-p, --props [jsonString]
参数对组件进行通用的支持。
例如,某Serverless Devs应用可以通过以下s.yaml
描述:
edition: 3.0.0access: "myaccess"
resources: website-starter: component: devsapp/website props: bucket: testbucket src: codeUri: ./ publishDir: ./build index: index.html region: cn-hangzhou hosts: - host: auto
并且,可以通过s website-starter deploy
,将website-starter
部分进行部署。
此时,如果通过cli
模式进行部署,可以不需要依赖上述Yaml,但是需要在命令行中,写上完整的参数信息:
s cli devsapp/website deploy -p "{\"bucket\":\"testbucket\",\"src\":{\"codeUri\":\"./\",\"publishDir\":\"./build\",\"index\":\"index.html\"},\"region\":\"cn-hangzhou\",\"hosts\":[{\"host\":\"auto\"}]}" -a myaccess
特定组件的支持
在 Serverless Devs 目前已经存在的组件中,已经有一些比较优秀且针对 Cli 模式设计的组件,例如fc3
组件,就是一款命令行模式优先的组件,通过该组件,可以快速的使用阿里云函数计算的一些接口,进行操作,例如:
-
查看阿里云函数计算的某个地区下某个函数信息:
Terminal window s cli fc3 info --region cn-hangzhou --function-name test -a myAccess -
调用阿里云函数计算的某个地区下某个函数:
Terminal window s cli fc3 invoke --region cn-hangzhou --function-name test -e "{\"key\" : \"val\"}" -a myAccess
除此之外,很多组件既可以对 Yaml 模式有比较好的支持,也会在某些情况下对 纯命令行模式,进行额外优化设计,例如 fc3
组件的线上线下资源同步操作:
$ s cli fc3 sync -hUsage: s cli fc3 sync [options]
Synchronize online resources to offline resources.
Examples with Yaml: $ s sync $ s sync --target-dir ./test --qualifier testAlias
Examples with CLI: $ s cli fc3 sync --region cn-hangzhou --function-name test -a default $ s cli fc3 sync --region cn-hangzhou --function-name s1\$f1 -a default...