Through the test template generation command, the simulated event structure of related triggers can be generated quickly. The generated simulated event structure can be debugged locally, or you can import it into a file and modify it according to your actual needs to implement your custom test template.
SCF CLI passed local generate-event
Command to generate the test template. The contents of the simulation test template for the specified trigger can be generated by executing different subcommands.
The command format for using triggers and detailed events within triggers is scf local generate-event {trigger} {trigger-event}
. For example, to simulate the PUT event of Cloud Object Storage (COS), the command is scf local generate-event cos put
.
More detailed triggers and events are shown in the following table:
Trigger | Event | Description |
---|---|---|
Apigateway | Proxy | API Gateway responds to request event |
Ckafka | Consume | Ckafka consumption message event |
Cmq | Notification | CMQ Topic message event |
Cos | Post/put/delete | Cloud Object Storage's POST, PUT and DELETE events |
Timer | Timeup | Timing trigger event |
The command to generate the test template outputs the JSON content of the test template directly in the terminal. Example:
$ scf local generate-event cos post
{
"Records": [
{
"cos": {
"cosSchemaVersion": "1.0",
"cosObject": {
"url": "http://testpic-1253970026.cos.ap-guangzhou.myqcloud.com/testfile",
"meta": {
"Content-Type": "",
"x-cos-request-id": "NWMxOWY4MGFfMjViMjU4NjRfMTUyMV8yNzhhZjM="
},
"key": "/1253970026/testpic/testfile",
"vid": "",
"size": 1029
},
"cosBucket": {
"region": "gz",
"name": "testpic",
"appid": "1253970026"
},
"cosNotificationId": "unkown"
},
"event": {
"eventVersion": "1.0",
"eventTime": 1545205770,
"requestParameters": {
"requestSourceIP": "59.37.125.38",
"requestHeaders": {
"Authorization":"q-signature=098ac7dfe9cf21116f946c4b4c29001c2b449b14"
}
},
"eventName": "cos:ObjectCreated:Post",
"reqid": 179398952,
"eventSource": "qcs::cos",
"eventQueue": "qcs:0:lambda:cd:appid/1253970026:default.printevent.$LATEST",
"reservedInfo": ""
}
}
]
}
The generated command can be directly used in the locally triggered calling function through the Shell pipeline.
For example, execute scf local generate-event cos post | scf local invoke -t template.yaml testfunction
Command, use the COS POST simulation event for the function trigger input parameter, and call the testfunction function locally.
By exporting to a file, you can quickly generate test template files. Based on the test template file, you can modify it to a more realistic test template. For example, execute scf local generate-event cos post > event.json
Command, a event.json file will be generated in the current Directory, which contains the contents of the COS POST test event.
SCF CLI can be accessed through scf eventdata list
View all debugging templates under a function.
scf eventdata list
The supported parameters are as follows:
Parameters | Abbreviated | Required | Description | Example |
---|---|---|---|---|
Name | -n | Yes | Function Name | -n hello_world |
Region | -r | No | To specify the area where the function is located, see Area list | -r ap-beijing |
Namespace | -ns | No | Namespace | -ns default |
- When region and namespace are not specified, the region and default namespaces in configure are used by default.
- Executable
scf configure get
View configure configuration information.
$scf eventdata list -n hello
[>] Region:ap-guangzhou
[>] Namespace:default
[>] Function:hello
TestmodelsName AddTime ModTime
apitest 2019-08-15 20:57:37 2019-08-15 20:57:37
costest 2019-08-15 20:58:31 2019-08-15 20:58:31
$scf eventdata list -r ap-guangzhou -ns default -n hello
[>] Region:ap-guangzhou
[>] Namespace:default
[>] Function:hello
TestmodelsName AddTime ModTime
apitest 2019-08-15 20:57:37 2019-08-15 20:57:37
costest 2019-08-15 20:58:31 2019-08-15 20:58:31
SCF CLI can be accessed through scf eventdata get
Download all debug templates under a function or specify a template. When downloading the template file, the scf_event_data folder is automatically created under the command execution Directory, and the template file is placed in this folder.
scf eventdata get
The supported parameters are as follows:
Parameters | Abbreviated | Required | Description | Example |
---|---|---|---|---|
Name | -n | Yes | Function Name | -n hello_world |
Region | -r | No | To specify the area where the function is located, see Area list | -r ap-beijing |
Namespace | -ns | No | Namespace | -ns default |
EVENT | -e | No | Template name (if left empty, download all by default) | -e apitest |
Output-dir | -d | No | Template storage path | -d. / |
Force | -f | No | When there is a template with the same name as the cloud locally, it will be forcibly overridden | None |
- When the output Directory is left unfilled, it will default to the current Directory.
- When region and namespace are not specified, the region and default namespaces in configure are used by default.
- Executable
scf configure get
View configure configuration information.
$scf eventdata get -n hello
[>] Downloading event-data: {apitest} ...
[o] Download event-data: {apitest} success
[>] Downloading event-data: {costest} ...
[o] Download event-data: {costest} success
$ ls
index.py scf_event_data template.yaml
$ ls scf_event_data/
apitest.json costest.json
When a template file with the same name as the cloud exists locally, the download will fail. If you want to overwrite the local file, use the
-f
Parameters.
$scf eventdata get -n hello -e apitest
[>] Downloading event-data: {apitest} ...
[o] Download event-data: {apitest} success
SCF CLI can be accessed through scf eventdata update
Upload the local template file to the cloud.
scf eventdata update
The supported parameters are as follows:
Parameters | Abbreviated | Required | Description | Example |
---|---|---|---|---|
Name | -n | Yes | Function Name | -n hello_world |
Dir | -d | Yes | Template path | -d. / |
Region | -r | No | To specify the area where the function is located, see Area list | -r ap-beijing |
Namespace | -ns | No | Namespace | -ns default |
Force | -f | No | When there is a template with the same name as the cloud locally, it will be forcibly overridden | None |
- When region and namespace are not specified, the region and default namespaces in configure are used by default.
- Executable
scf configure get
View configure configuration information.- If dir is assigned to Directory, all json files under that Directory will be uploaded. If dir is specified to a specific file, the specified file is uploaded.
$scf eventdata update -n hello -d scf_event_data/
[>] Region:ap-guangzhou
[>] Namespace:default
[>] Function:hello
[>] Eventdata {apitest} exist in remote,updating event...
[o] Eventdata {apitest} update success!
[>] Eventdata {costest} exist in remote,updating event...
[o] Eventdata {costest} update success!
When a template file with the same name as the local file exists on the cloud, the upload fails. If you want to overwrite the cloud file, use the
-f
Parameters.
$scf eventdata update -n hello -d scf_event_data/apitest.json
[>] Region:ap-guangzhou
[>] Namespace:default
[>] Function:hello
[o] Eventdata {apitest} update success!
Was this page helpful?