跳到主要内容

云函数

callFunction

1. 接口描述

接口功能:执行云函数

接口声明:callFunction(object: IFunctionParams, opts: Object): Promise<Object>

2. 输入参数

字段类型必填说明
objectIFunctionParams云函数调用请求参数
optsObject自定义配置,目前支持 SDK 请求超时时间设置,{timeout: number}
IFunctionParams
字段类型必填说明
namestring云函数名称
dataobject云函数参数

3. 返回结果

字段类型必填说明
codestring状态码,操作成功则不返回
messagestring错误描述
resultobject云函数执行结果
requestIdstring请求序列号,用于错误排查

4. 示例代码

// 云函数环境下示例代码

// 初始化
const tcb = require('@cloudbase/node-sdk')
const app = tcb.init({
env: 'xxx'
})

exports.main = async (event, context) => {
const res = await app.callFunction({
name: 'test',
data: { a: 1 }
})
console.log(res) // 打印函数调用结果

const res1 = await app.callFunction(
{
name: 'test',
data: { a: 1 }
},
{
timeout: 5000
}
)
console.log(res1)
}