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 参数表示覆盖上一次名为custom-profile的配置

Serverless 入门(五)- 常用命令_第1张图片

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

2. 创建服务

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

  • --template aws-nodejs 表示采用 aws-nodejs 模板
  • --path hello-world 表示创建后的服务文件夹叫hello-world

加强版配置命令
我们先来看看 serverless create 都是哪些参数:
--template 必选参数,用于指定模板名,不能跟 --template-url--template-path 同时使用。
--template-url 用于创建线上模板,不能跟 --template--template-path 同时使用。
--template-path 用于创建本地模板,不能跟 --template--template-url 同时使用。
--path 指定服务创建后的文件夹.
--name 指定 serverless.yml 里的服务名

下面列举了几种不同的用法:

  • 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. 调用

调用的常用命令在上一篇有详细讲解,点击查看

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

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

相关文章

  • Serverless 入门(一) - 创建 IAM https://www.jianshu.com/p/9fb731a799e2
  • Serverless 入门(二) - HelloWord https://www.jianshu.com/p/ddf2ffda5f63
  • Serverless 入门(三)- 初始项目解读 https://www.jianshu.com/p/8baba2a8fe9f
  • Serverless 入门(四)- 如何调试 https://www.jianshu.com/p/58d30915de8a
  • Serverless 入门(五)- 常用命令 https://www.jianshu.com/p/28f001ea9d9d
  • Serverless 入门(六)- DynamoDB 数据库(上) https://www.jianshu.com/p/c313b61d1cbf
  • Serverless 入门(七)- DynamoDB 数据库(中) https://www.jianshu.com/p/05e7f4ccd6fe
  • Serverless 入门(八)- DynamoDB 数据库(下) https://www.jianshu.com/p/0f9f1561ec46
  • Serverless 入门(九)- 权限 https://www.jianshu.com/p/97228749d761

你可能感兴趣的:(Serverless 入门(五)- 常用命令)