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的配置


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锅

相关文章

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。