zl程序教程

您现在的位置是:首页 >  其它

当前栏目

【AGC】【serverless】【云函数】云函数常见问题

函数 常见问题 Serverless AGC
2023-09-11 14:20:22 时间

1、【问题描述】

在云函数里往云数据库里插入数据返回的是180000,这是正常吗?

code: 180000,

message:"Call handler error: RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: 1 at ServerResponse.writeHead (_http_server.js:259:11) at ServerResponse._implicitHeader (_http_server.js:250:8) at ServerResponse.end (_http_outgoing.js:837:10) at ServerResponse.send (/home/wisefunction/runtime/node_modules/express/lib/response.js:221:10) at setBodyV1 (/home/wisefunction/runtime/functions/invoke_func.js:329:40) at responseFromOutputV1 (/home/wisefunction/runtime/functions/invoke_func.js:228:9) at Context.callback (/home/wisefunction/runtime/functions/invoke_func.js:187:17) at ShopCollect_Add (/dcache/layer/func/handler.js:51:9) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async exports.invokeFunc (/home/wisefunction/runtime/functions/invoke_func.js:127:9)"

【解决方案】

回调代码需要修改一下,如下图:

cke_583.png

样例:

cke_1408.png

参考:

cke_2315.png

2、【问题描述】

云函数里的AUTH触发器怎么使用?

已经按照文档在后台对应的云函数里配置了,所需的AUTH触发器。

这触发器在客户端怎么触发吗?跟http触发器一样触发吗?

有没有相关例子?

【解决方案】

1、云函数添加了AUTH触发器后,在用户执行注册、销户、登录、登出动作时,云函数的event对象会自动触发返回相应信息。

cke_3972.png

通过event对象获取信息后,您可以根据需求在云函数中做相应处理操作。

2、客户端无法直接调用和监听触发器。典型应用场景。

3、【问题描述】

云函数如何调用云数据库?可以给个例子代码吗?

【解决方案】

参考官网案例

4、【问题描述】

云函数里的层如何调用?

比如我在“层”的压缩包里放了config/config.txt,那么我在云函数里怎么调用这个文件?

【解决方案】

层的用法和放在函数里的用法是相同的。例如

let test = request('test.js') //文件来自层

层的目录是:/dcache/layer,函数的目录是/dcache/layer/func 。

 

欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh