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 myServiceserverless create --template-url https://github.com/serverless/serverless/tree/master/lib/plugins/create/templates/aws-nodejs --path myServiceserverless 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)文章
- Serverless 入門(一) - 創(chuàng)建 IAM http://www.itdecent.cn/p/9fb731a799e2
- Serverless 入門(二) - HelloWord http://www.itdecent.cn/p/ddf2ffda5f63
- Serverless 入門(三)- 初始項目解讀 http://www.itdecent.cn/p/8baba2a8fe9f
- Serverless 入門(四)- 如何調(diào)試 http://www.itdecent.cn/p/58d30915de8a
- Serverless 入門(五)- 常用命令 http://www.itdecent.cn/p/28f001ea9d9d
- Serverless 入門(六)- DynamoDB 數(shù)據(jù)庫(上) http://www.itdecent.cn/p/c313b61d1cbf
- Serverless 入門(七)- DynamoDB 數(shù)據(jù)庫(中) http://www.itdecent.cn/p/05e7f4ccd6fe
- Serverless 入門(八)- DynamoDB 數(shù)據(jù)庫(下) http://www.itdecent.cn/p/0f9f1561ec46
- Serverless 入門(九)- 權(quán)限 http://www.itdecent.cn/p/97228749d761