文档首页 > > Sandbox 调试工具使用指南> 快速入门> 生成本地事件

生成本地事件

分享
更新时间:2020/05/13 GMT+08:00

使用以下命令生成模拟JSON事件记录。这些记录可以在调用函数时使用。

$ hss localEvent <service> [service-options]

HSS本地事件命令的输出可以保存在本地文件中,然后可以在HSS调用命令中使用该文件,如下所示。

$ hss localEvent obs --bucket bucket1 > events.json
$ hss invoke -e events.json <FunctionStage>

HSS本地事件命令的输出可以直接传送给HSS调用命令,如下所示。

$ hss localEvent obs --bucket bucket2 | hss invoke <FunctionStage>

如果使用来自非stdin输入指定事件文件,它将优先于来自stdin的输入。

由于交互模式hss相关命令不支持|,所以该命令可替换成以下。

使用localEvent -o参数生成本地文件。

> localEvent obs --bucket bucket2  -o <object file>

使用invoke –e参数执行本地文件。

>Invoke -e  <object file>  <FunctionStage>

选项说明

该命令可以用于从华为云服务(如OBS,SMN和DMS)中生成典型事件。 <service>可以是以下之一。

  • obs:生成华为云OBS事件
  • smn:生成华为云SMN事件
  • dms:生成华为云DMS事件
  • dis:生成华为云DIS事件
  • apig:生成华为云APIG事件
  • lts:生成华为云LTS事件
  • cts:生成华为云CTS事件
表1 OBS options

options

说明

是否必选

--region, -r

OBS region

可选

缺省值:cn-north-1

--bucket, -b

OBS bucket name

可选

缺省值: example-bucket

--key, -k

OBS key name

可选

缺省值:example/key

--objectFile value, -o

logged to the objectFile

可选

表2 SMN options

options

说明

是否必选

--message, -m

SMN message

可选

缺省值:<default message>

--subject, -s

SMN subject

可选

缺省值:<default subject>

--topic, -t

SMN topic

可选

缺省值:<default topic>

--objectFile value, -o

logged to the objectFile

可选

表3 DMS options

options

说明

是否必选

--region, -r

DMS region

可选

缺省值:cn-north-1

--queueId, -qid

DMS queue id

可选

缺省值:<default QID>

--consumerGroupId, -gid

DMS consumer group id

可选

缺省值:<default CGID>

--messages, -m

DMS message

可选

缺省值:<default messages>

--objectFile value, -o

logged to the objectFile

可选

表4 DIS options

options

说明

是否必选

--stream value, -s

DIS stream

可选

缺省值:mystream

--tag value, -t

DIS position of reading the data

可选

缺省值:LATEST

--records value, -r

DIS data in JSON

可选

缺省值:[{\"partition_key\": \"shardId_0000000000\", \"data\": \"d2VsY29tZQ==\", \"sequence_number\": \"0\"}]

--nextPartitionCursor value, --npc

The next partition cursor

可选

缺省值如“说明”中所示。

--verbose, -v

Provide verbose information

可选

--objectFile value, -o

logged to the objectFile

可选

--nextPartitionCursor value, --npc缺省值如下:

eyJnZXRJdGVyYXRvclBhcmFtIjp7InN0cmVhbS1uYW1lIjoiZGlzLXN3dGVzdCIsInBhcnRpdGlvbi1pZCI6InNoYXJkSWQtMDAwMDAwMDAwMCIsImN1cnNvci10eXBlIjoiVFJJTV9IT1JJWk9OIiwic3RhcnRpbmctc2VxdWVuY2UtbnVtYmVyIjoiNCJ9LCJnZW5lcmF0ZVRpbWVzdGFtcCI6MTUwOTYwNjM5MjE5MX0

表5 APIG options

options

说明

是否必选

--method value, -m

The http request method

可选

缺省值:GET

--path value, -p

The http request path

可选

缺省值:/mytest

--body value, -b

The http request body

可选

--resptype value, -t

The http response type

可选

缺省值:html

--stage value, -s

The release stage

可选

缺省值:RELEASE

--host value, -a

The release address of host

可选

缺省值:50eedf92-c9ad-4ac0-827e-d7c11415d4f1.apigw.cn-north-1.huaweicloud.com

--objectFile value, -o

logged to the objectFile

可选

表6 LTS options

options

说明

是否必选

--data value, -d

data of logs encoded by base64

可选

缺省值如“说明”中所示。

--objectFile value, -o

logged to the objectFile

可选

--data value, -d缺省值如下:

ewogICAgICAgICJsb2dzIjpbewogICAgICAgICAgICAgICAgIm1lc3NhZ2UiOiIyMDE4LTA2LTI2LzE4OjQwOjUzIFtJTkZdIFtjb25maWcuZ286NzJdIFN1Y2Nlc3NmdWxseSBsb2FkZWQgZ2VuZXJhbCBjb25maWd1cmF0aW9uIGZpbGVcXHJcXG4iLAogICAgICAgICAgICAgICAgInRpbWUiOjE1MzAwMDk2NTMwNTksCiAgICAgICAgICAgICAgICAiaG9zdF9uYW1lIjoiZWNzLXRlc3RhZ2VudC5ub3ZhbG9jYWwiLAogICAgICAgICAgICAgICAgImlwIjoiMTkyLjE2OC4xLjk4IiwKICAgICAgICAgICAgICAgICJwYXRoIjoidXNyL2xvY2FsL3RlbGVzY29wZS9sb2cvY29tbW9uLmxvZyIsCiAgICAgICAgICAgICAgICAibG9nX3VpZCI6IjY2M2Q2OTMwLTc5MmQtMTFlOC04YjA4LTI4NmVkNDg4Y2U3MCIsCiAgICAgICAgICAgICAgICAibGluZV9ubyI6NjE1CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICJtZXNzYWdlIjoiMjAxOC0wNi0yNi8xODo0MDo1MyBbV1JOXSBbY29uZmlnLmdvOjgyXSBUaGUgcHJvamVjdElkIG9yIGluc3RhbmNlSWQgb2YgY29uZmlnLmpzb24gaXMgbm90IGNvbnNpc3RlbnQgd2l0aCBtZXRhZGF0YSwgdXNlIG1ldGFkYXRhLlxcbiIsCiAgICAgICAgICAgICAgICAidGltZSI6MTUzMDAwOTY1MzA1OSwKICAgICAgICAgICAgICAgICJob3N0X25hbWUiOiJlY3MtdGVzdGFnZW50Lm5vdmFsb2NhbCIsCiAgICAgICAgICAgICAgICAiaXAiOiIxOTIuMTY4LjEuOTgiLAogICAgICAgICAgICAgICAgInBhdGgiOiIvdXNyL2xvY2FsL3RlbGVzY29wZS9sb2cvY29tbW9uLmxvZyIsCiAgICAgICAgICAgICAgICAibG9nX3VpZCI6IjY2M2Q2OTMwLTc5MmQtMTFlOC04YjA5LTI4NmVkNDg4Y2U3MCIsCiAgICAgICAgICAgICAgICAibGluZV9ubyI6NjE2CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICJtZXNzYWdlIjoiIEluIGNvbmYuanNvbiwgcHJvamVjdElkIGlzIFtdLCBpbnN0YW5jZUlkIGlzIFtdLiBNZXRhRGF0YSBpcyB7NDU0MzI5M2EtNWIyYy00NGM0LWI3YTAtZGUyMThmN2YyZmE2IDYyODBlMTcwYmQ5MzRmNjBhNGQ4NTFjZjVjYTA1MTI5ICB9XFxyXFxuIiwKICAgICAgICAgICAgICAgICJ0aW1lIjoxNTMwMDA5NjUzMDU5LAogICAgICAgICAgICAgICAgImhvc3RfbmFtZSI6ImVjcy10ZXN0YWdlbnQubm92YWxvY2FsIiwKICAgICAgICAgICAgICAgICJpcCI6IjE5Mi4xNjguMS45OCIsCiAgICAgICAgICAgICAgICAicGF0aCI6Ii91c3IvbG9jYWwvdGVsZXNjb3BlL2xvZy9jb21tb24ubG9nIiwKICAgICAgICAgICAgICAgICJsb2dfdWlkIjoiNjYzZDY5MzAtNzkyZC0xMWU4LThiMGEtMjg2ZWQ0ODhjZTcwIiwKICAgICAgICAgICAgICAgICJsaW5lX25vIjo2MTcKICAgICAgICAgICAgfQogICAgICAgICAgICBdLAogICAgICAgICJvd25lciI6ICI2MjgwZTE3MGJkOTM0ZjYwYTRkODUxY2Y1Y2EwNTEyOSIsCiAgICAgICAgImxvZ19ncm91cF9pZCI6ICI5N2E5ZDI4NC00NDQ4LTExZTgtOGZhNC0yODZlZDQ4OGNlNzAiLAogICAgICAgICJsb2dfdG9waWNfaWQiOiAiMWE5Njc1YTctNzg0ZC0xMWU4LTlmNzAtMjg2ZWQ0ODhjZTcwIgogICAgICAgIH0=

表7 CTS options

options

说明

是否必选

--time value, -t

The time of sender

可选

缺省值:2018/08/01 08:54:07 GMT+08:00

--userName value, --un

Requested user name

可选

缺省值:<default userName>

--userId value, --ui

.Requested user id

可选

缺省值:<default userID>

--domainName value, --dn

Requested user domain.name

可选

缺省值:<default domainName>

--domainId value, --di

Requested user domain.id

可选

缺省值:<default domainId>

--request value, --rq

Event request content in JSON

可选

缺省值:{}

--response value, --rs

.Event response content in JSON

可选

缺省值:{}

--code value, -c

Event response code

可选

缺省值:204

--serviceType value, --st

Sender service

可选

缺省值:FunctionGraph

--resourceType value, --rty

Sender resource type

可选

缺省值:graph

--resourceName value, --rn

Sender resource name

可选

缺省值:workflow-2be1

--resourceId value, --ri

Sender resource id

可选

缺省值:<default resource id>

--traceName value, --tn

Track record name

可选

缺省值:deleteGraph

--traceType value, --tt

Track record type

可选

缺省值:ConsoleAction

--recordTime value, --rtm

Time when tracking records

可选

缺省值:2018/08/01 08:54:07 GMT+08:00

--traceId value, --ti

Track record id

可选

缺省值:<default traceId>

--traceStatus value, --ts

Track record status

可选

缺省值:normal

--objectFile value, -o

logged to the objectFile

可选

事件详情

  • DMS Record
      {
        "QueueID": "39907254-5321-4b90-bad2-f82455ff3ead",
        "Region": "cn-north-1",
        "Messages": [
            {
                "Body": "this is body message",
                "Attributes": {
                    "weight": "80",
                    "size": "100"
                }
            }
        ],
        "EventType": "MessageCreated",
        "ConsumerGroupID": "g-06c2bff5-67db-4055-ba4e-a31bb09c3485"
      }
  • SMN Record
      {
        "record": [
            {
                "event_version": "1.0",
                "smn": {
                    "topic_urn": "urn:smn:cn-north-1:0162c0f220284698b77a3d264376343a:test3",
                    "timestamp": "2018-01-09T07:11:40Z",
                    "message_attributes": null,
                    "message": "this is smn message content",
                    "type": "notification",
                    "message_id": "a51671f77d4a479cacb09e2cd591a983",
                    "subject": "this is smn message subject"
                },
                "event_subscription_urn":
                    "urn:fss:cn-north-1:0162c0f220284698b77a3d264376343a:function:default:
                          read-smn-message:latest",
                "event_source": "smn"
            }
        ]
      }
  • DIS Record
    {
        "ShardID": "shardId-0000000000",
        "Message": {
            "next_partition_cursor": "eyJnZXRJdGVyYXRvclBhcmFtIjp7InN0cmVhbS1uYW1lIjoiZGlzLXN3dGVzdCIsInBhcnRpdGlvbi1pZCI6InNoYXJkSWQtMDAwMDAwMDAwMCIsImN1cnNvci10eXBlIjoiVFJJTV9IT1JJWk9OIiwic3RhcnRpbmctc2VxdWVuY2UtbnVtYmVyIjoiNCJ9LCJnZW5lcmF0ZVRpbWVzdGFtcCI6MTUwOTYwNjM5MjE5MX0",
            "records": [{"partition_key": "shardId_0000000000", "data": "d2VsY29tZQ==", "sequence_number": "0"}],
            "millis_behind_latest": 0
        },
        "Tag": "LATEST",
        "StreamName": "mystream"
    }
  • APIG Record
    {
        "body": "",
        "requestContext": {
            "apiId": "bc1dcffd-aa35-474d-897c-d53425a4c08e",
            "requestId": "11cdcdcf33949dc6d722640a13091c77",
            "stage": "RELEASE"
        },
        "queryStringParameters": {
            "responseType": "html"
        },
        "httpMethod": "GET",
        "pathParameters": {},
        "headers": {
            "accept-language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
            "accept-encoding": "gzip, deflate, br",
            "x-forwarded-port": "443",
            "x-forwarded-for": "127.0.0.1",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "upgrade-insecure-requests": "1",
            "host": "50eedf92-c9ad-4ac0-827e-d7c11415d4f1.apigw.cn-north-1.huaweicloud.com",
            "x-forwarded-proto": "",
            "pragma": "no-cache",
            "cache-control": "no-cache",
            "x-real-ip": "127.0.0.1",
            "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0"
        },
        "path": "/mytest",
        "isBase64Encoded": true
    }
  • LTS Record
    {
      "lts": {
        "data": {
            "logs":[{
                    "message":"2018-06-26/18:40:53 [INF] [config.go:72] Successfully loaded general configuration file\\r\\n",
                    "time":1530009653059,
                    "host_name":"ecs-testagent.novalocal",
                    "ip":"192.168.1.98",
                    "path":"usr/local/telescope/log/common.log",
                    "log_uid":"663d6930-792d-11e8-8b08-286ed488ce70",
                    "line_no":615
                },
                ],
            "owner": "6280e170bd934f60a4d851cf5ca05129",
            "log_group_id": "97a9d284-4448-11e8-8fa4-286ed488ce70",
            "log_topic_id": "1a9675a7-784d-11e8-9f70-286ed488ce70"
            }
      }
    }
  • CTS Record
    {
      "cts":  {
            "time": "2018/08/01 08:54:07 GMT+08:00",
            "user": {
                "name": "userName",
                "id": "5b726c4fbfd84821ba866bafaaf56aax",
                "domain": {
                    "name": "domainName",
                    "id": "b2b3853af40448fcb9e40dxj89505ba"
                }
            },
            "request": {},
            "response": {},
            "code": 204,
            "service_type": "FunctionGraph",
            "resource_type": "graph",
            "resource_name": "workflow-2be1",
            "resource_id": "urn:fgs:cn-north-1:2d1d891d93054bbaa69b9e866c0971ac:graph:workflow-2be1",
            "trace_name": "deleteGraph",
            "trace_type": "ConsoleAction",
            "record_time": "2018/08/01 08:54:07 GMT+08:00",
            "trace_id": "69be64a7-0233-11e8-82e4-e5d37911193e",
            "trace_status": "normal"
        }
    }
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!非常感谢您的反馈,我们会继续努力做到更好!
反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问