serverless create
基本命令
serverless create --template aws-nodejs
該命令用於在當前目錄使用aws-nodejs template創建一個工程。
命令參數
--template
可以縮寫爲-t
用於指定模板名稱
--template-url
可以縮寫爲-u
用於指定遠程模板的地址,比如在github上的模板
--template-path
用於指定本地模板的路徑
以上三個用於指定tempalte的選項,必須選擇一個使用
--path
可以縮寫爲-p
用於指定在哪個路徑下創建工程文件,如果指定路徑不存在,則會自動創建,未指定的話會在當前目錄創建工程文件,包括項目實例源碼,serverless.yml等文件。
--name
可以縮寫爲-n
用於指定創建的serverless.yml文件中的service的名稱。
如果指定了path,而沒有指定name,則默認會使用path作爲serverless.yml文件中的service的名稱。
可選Templates
可以通過serverless create --help命令查看當前提供的template信息
$ serverless create --help
Plugin: Create
create ........................ Create new Serverless service
--template / -t .................... Template for the service. Available templates:
"aws-clojure-gradle", "aws-clojurescript-gradle", "aws-nodejs", "aws-nodejs-typescript", "aws-alexa-typescript", "aws-nodejs-ecma-script", "aws-python", "aws-python3"
"aws-groovy-gradle", "aws-java-maven", "aws-java-gradle", "aws-kotlin-jvm-maven", "aws-kotlin-jvm-gradle", "aws-kotlin-nodejs-gradle", "aws-scala-sbt", "aws-csharp"
"aws-fsharp", "aws-go", "aws-go-dep", "aws-go-mod", "aws-ruby", "aws-provided"
"tencent-go", "tencent-nodejs", "tencent-python", "tencent-php"
"azure-csharp", "azure-nodejs", "azure-nodejs-typescript", "azure-python"
"cloudflare-workers", "cloudflare-workers-enterprise", "cloudflare-workers-rust"
"fn-nodejs", "fn-go"
"google-nodejs", "google-python", "google-go"
"kubeless-python", "kubeless-nodejs"
"knative-docker"
"openwhisk-java-maven", "openwhisk-nodejs", "openwhisk-php", "openwhisk-python", "openwhisk-ruby", "openwhisk-swift"
"spotinst-nodejs", "spotinst-python", "spotinst-ruby", "spotinst-java8"
"twilio-nodejs"
"aliyun-nodejs"
"plugin"
"hello-world"
--template-url / -u ................ Template URL for the service. Supports: GitHub, BitBucket
--template-path .................... Template local path for the service.
--path / -p ........................ The path where the service should be created (e.g. --path my-service)
--name / -n ........................ Name for the service. Overwrites the default name of the created service.
創建service
在當前目錄創建service
serverless create --template aws-nodejs
在指定目錄創建service
serverless create --template aws-nodejs --path myService
使用遠程template創建service
serverless create --template-url https://github.com/serverless/serverless/tree/master/lib/plugins/create/templates/aws-nodejs --path myService
使用本地template創建service
serverless create --template-path path/to/my/template/folder --path path/to/my/service --name my-new-service
serverless install
用於將遠程serverless工程拉取到本地
基本命令
serverless install --url https://github.com/some/service
命令參數
--url
縮寫爲-u
遠程service的地址
--name
縮寫爲-n
在本地爲拉取的service重新命名
示例
從GitHub URL下載service到本地當前工作目錄
serverless install --url https://github.com/pmuens/serverless-crud
該命令會從指定的GitHub下載.zip文件,在當前工作目錄下創建名爲 serverless-crud的目錄並將.zip文件解壓到serverless-crud目錄。
從GitHub URL下載service並重新命名
serverless install --url https://github.com/pmuens/serverless-crud --name my-crud
該命令會從指定的GitHub下載.zip文件,在當前工作目錄下創建名爲 my-crud的目錄並將.zip文件解壓到my-crud目錄,同時修改my-crud根目錄下serverless.yml文件內的service名字爲my-crud。
參考
https://www.serverless.com/framework/docs/providers/aws/cli-reference/create/
https://www.serverless.com/framework/docs/providers/aws/cli-reference/install/