Serverless 入門(五)- 常用命令

1.配置證書

serverless config credentials

常用配置命令:serverless config credentials --provider aws --key aws_access_key_id --secret aws_secret_access_key

這命令中的兩個 Key 需要在 AWS 后臺查找,aws 表示使用 Amazon AWS 平臺

加強版配置命令:serverless config credentials --provider aws --key aws_access_key_id --secret aws_secret_access_key --profile custom-profile --overwrite

  • --profile 表示添加自定義證書配置,名稱為custom-profile,名稱可以隨便取
  • --overwrite 參數(shù)表示覆蓋上一次名為custom-profile的配置


cat ~/.aws/credentials 命令可以查看

2. 創(chuàng)建服務(wù)

常用配置命令:serverless create --template aws-nodejs --path hello-world

  • --template aws-nodejs 表示采用 aws-nodejs 模板
  • --path hello-world 表示創(chuàng)建后的服務(wù)文件夾叫hello-world

加強版配置命令
我們先來看看 serverless create 都是哪些參數(shù):
--template 必選參數(shù),用于指定模板名,不能跟 --template-url--template-path 同時使用。
--template-url 用于創(chuàng)建線上模板,不能跟 --template--template-path 同時使用。
--template-path 用于創(chuàng)建本地模板,不能跟 --template--template-url 同時使用。
--path 指定服務(wù)創(chuàng)建后的文件夾.
--name 指定 serverless.yml 里的服務(wù)名

下面列舉了幾種不同的用法:

  • serverless create --template aws-nodejs --path myService

  • serverless create --template-url https://github.com/serverless/serverless/tree/master/lib/plugins/create/templates/aws-nodejs --path myService

  • serverless create --template-path path/to/my/template/folder --path path/to/my/service --name my-new-service

除了名為 aws-nodejs 模板外,還有非常多其它模板供大家選擇,見如下列表:

aws-clojurescript-gradle
aws-clojure-gradle
aws-nodejs
aws-nodejs-typescript
aws-alexa-typescript
aws-nodejs-ecma-script
aws-python
aws-python3
aws-ruby
aws-provided
aws-kotlin-jvm-maven
aws-kotlin-jvm-gradle
aws-kotlin-nodejs-gradle
aws-groovy-gradle
aws-java-maven
aws-java-gradle
aws-scala-sbt
aws-csharp
aws-fsharp
aws-go
aws-go-dep
aws-go-mod
plugin

基本涵蓋了當前流行的編程語言。

3. 部署

常用部署命令serverless deploy

加強版部署命令serverless deploy list

查看線上代碼部署了幾次,信息如下:

 deploy list
Serverless: Listing deployments:
Serverless: -------------
Serverless: Timestamp: 1552032409229
Serverless: Datetime: 2019-03-08T08:06:49.229Z
Serverless: Files:
Serverless: - compiled-cloudformation-template.json
Serverless: - hello-world.zip
.... 省略好多行 ...
Serverless: -------------
Serverless: Timestamp: 1552234275131
Serverless: Datetime: 2019-03-10T16:11:15.131Z
Serverless: Files:
Serverless: - compiled-cloudformation-template.json
Serverless: - hello-world.zip
  • serverless deploy list functions -f hello -s dev
    查看線上 dev 版代碼部署了幾次,信息如下:
Serverless: Listing functions and their last 5 versions:
Serverless: -------------
Serverless: hello: $LATEST, 1, 2, 3, 4

4. 調(diào)用

調(diào)用的常用命令在上一篇有詳細講解,點擊查看

  • serverless invoke -f hello -l -d Kenny鍋

  • serverless invoke local -f hello -l -d Kenny鍋

相關(guān)文章

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容