AWS Serverless CLI命令参考7--logs&metrics&info&print

logs

用于显示指定的lambda函数的log。

该命令最多返回1MB的log数据,可以使用--filter参数对返回的log进行筛选。

基本命令

serverless logs -f hello

命令参数

--function

 缩写为-f

用于指定需要获取log的目标lambda函数的名字,注意这个名字是serverless中定义function的key,而不是函数配置的name属性。

AWS Serverless CLI命令参考7--logs&metrics&info&print_第1张图片

--stage

缩写为-s

用于指定获取log的stage。如果未指定该参数,plugin会使用serverless.yml中指定的stage,如果serverless.yml中未指定stage,则默认从dev stage读取log。

--region

缩写为-r

用于指定获取log的region。如果未指定该参数,plugin会使用serverless.yml中指定的region,如果serverless.yml中未指定region,则默认从us-east-1region读取log。

--startTime 

用于指定获取log的起始时间。支持的时间格式如下:

30m                   # since 30 minutes ago
2h                    # since 2 hours ago
3d                    # since 3 days ago

2013-02-08            # A calendar date part
2013-W06-5            # A week date part
2013-039              # An ordinal date part

20130208              # Basic (short) full date
2013W065              # Basic (short) week, weekday
2013W06               # Basic (short) week only
2013050               # Basic (short) ordinal date

2013-02-08T09         # An hour time part separated by a T
20130208T080910,123   # Short date and time up to ms, separated by comma
20130208T080910.123   # Short date and time up to ms
20130208T080910       # Short date and time up to seconds
20130208T0809         # Short date and time up to minutes
20130208T08           # Short date and time, hours only

--filter 

用于指定筛选log,只有包含改参数指定的字符串的log才会被返回。

--tail 

缩写为-t

用于选择尾随日志并继续监听终端会话中的新日志

--interval

 缩写为-i 

于--tail参数组合使用,用于指定拉取新日志的时间间隔,默认值为 1000ms.

示例

获取5个小时内的log

serverless logs -f hello --startTime 5h

监听新的日志

serverless logs -f hello --filter serverless

metrics

用于查看service的metrics。

基本命令

serverless metrics

命令参数

--function

 缩写为-f

用于指定查看指定函数的metrics,注意这个名字是serverless中定义function的key,而不是函数配置的name属性。

AWS Serverless CLI命令参考7--logs&metrics&info&print_第2张图片

--stage

缩写为-s

用于指定查看metrics的stage。如果未指定该参数,plugin会使用serverless.yml中指定的stage,如果serverless.yml中未指定stage,则默认从dev stage读取log。

--region

缩写为-r

用于指定查看metrics的region。如果未指定该参数,plugin会使用serverless.yml中指定的region,如果serverless.yml中未指定region,则默认从us-east-1region读取log。

--startTime 

用于指定查看metrics的起始时间。支持的时间格式如下:2010-10-20146970576130m (30 minutes ago), 2h (2 hours ago) or 3d (3 days ago)). 时间应使用 ISO 8601格式. 默认值为24h 之前。

--endTime 

用于指定查看metrics的结束时间。支持的时间格式如下:2010-10-20146970576130m (30 minutes ago), 2h (2 hours ago) or 3d (3 days ago)). 时间应使用 ISO 8601格式. 默认值为now。

示例

查看24小时内整个service的metrics

serverless metrics

查看某个时间段内整个service的metrics

serverless metrics --startTime 2016-01-01 --endTime 2016-01-02

查看24小时内某个function的metrics

serverless metrics --function hello

查看某个时间段内某个function的metrics

serverless metrics --function hello --startTime 2016-01-01 --endTime 2016-01-02

info

用于显示部署的service的信息。

基本命令

$ serverless info --verbose

Service Information
service: my-serverless-service
stage: dev
region: us-east-1
api keys:
  myKey: some123valid456api789key1011for1213api1415gateway
endpoints:
  GET - https://dxaynpuzd4.execute-api.us-east-1.amazonaws.com/dev/users
functions:
  my-serverless-service-dev-hello

Stack Outputs
CloudFrontUrl: d2d10e2tyk1pei.cloudfront.net
ScreenshotBucket: dev-svdgraaf-screenshots
ServiceEndpoint: https://12341jc801.execute-api.us-east-1.amazonaws.com/dev
ServerlessDeploymentBucketName: lambda-screenshots-dev-serverlessdeploymentbucket-15b7pkc04f98a

命令参数

 

--stage

缩写为-s

用于指定service的stage

--region

缩写为-r

用于指定service的region

--verbose

缩写为-v

用于显示stack的输出

print

用于显示将所有的参数填充之后的serverless.yml配置文件

基本命令

serverless print

命令参数

--format

指定以何种格式打印配置文件,支持的格式有:"yaml", "json", "text",默认格式为 yaml

--path

只打印一个具体的属性,比如provider.name

--transform 

转换函数,目前仅支持keys,表示只显示key信息

示例

源文件:

service: my-service

custom:
  bucketName: test

provider:
  name: aws
  runtime: nodejs12.x
  stage: ${opt:stage, "dev"}

functions:
  hello:
    handler: handler.hello

resources:
  Resources:
    MyBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:custom.bucketName}

使用sls print解析后的文件

$ sls print
service: my-service
custom:
  bucketName: test
provider:
  name: aws
  runtime: nodejs12.x
  stage: dev # <-- Resolved
functions:
  hello:
    handler: handler.hello
resources:
  Resources:
    MyBucket:
      Type: 'AWS::S3::Bucket'
      Properties:
        BucketName: test # <-- Resolved

显示provider名称:

sls print --path provider.name --format text

显示所有的lambda函数的名称:

sls print --path functions --transform keys --format text

参考

https://www.serverless.com/framework/docs/providers/aws/cli-reference/logs/

https://www.serverless.com/framework/docs/providers/aws/cli-reference/metrics/

https://www.serverless.com/framework/docs/providers/aws/cli-reference/info/

https://www.serverless.com/framework/docs/providers/aws/cli-reference/print/

你可能感兴趣的:(serverless,aws)