文档

如何使用云函数?

更新时间:

当你对存储在SyncStore的数据发生变化的时候“感兴趣”,我们提供了基于事件触发的云端函数计算服务 —— YunFunction。你只要在感兴趣的数据上【创建触发器】,使得数据变化时,系统自动调用关联的YunFunction;那么,当函数被调用时,相应数据会透传给函数,参与函数计算逻辑。

主要操作步骤见下:

创建函数

说明

当前提供了函数包的方式进行函数的创建,函数的运行环境(Runtime)当前仅支持NodeJS(4.4+)。函数包是以.zip为后缀的、标准的npm包。

函数包创建

>mkdir yunfunction_demo
>cd yunfunction_demo
>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (yunfunction_demo)
version: (1.0.0)
description: This is a yunfunction demo
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to yunfunction_demo/package.json:

{
  "name": "yunfunction_demo",
  "version": "1.0.0",
  "description": "This is a yunfunction demo",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this ok? (yes) yes

TODO 编写代码逻辑...

>zip -q -r yunfunction_demo.zip *

样例:yunfunction_demo.zip

上传包文件

upload_func_pkg

进入代码管理页面,选择本地准备好的函数包文件并上传。

部署函数

deploy_func

进入代码管理页面,在已上传的函数包记录中,点击部署,在部署函数表单中选择部署环境,点击确定。

运行(调试)函数

invoke_func

进入代码管理页面,在已上传的函数包记录中,点击运行,在运行表单中选择目标函数、运行环境及函数入参,点击确定。

注:入参将传递给函数的第一个参数(如:event)

查看运行日志

func_log

进入日志查询页面,选择目标函数及环境,点击搜索。

创建触发器

create_trigger

进入触发器页面,选择namespace,点击创建触发器,配置触发器关联的触发源、运行环境、选择目标函数及函数调用模式,点击确定。

  • 本页导读 (0)
文档反馈