COS 是腾讯云用于存储一些资源文件的服务。
使用方式
在 f.yml 中配置函数和触发器。
service: midway-faas-examplesprovider:name: tencentfunctions:cosTrigger:handler: index.handlerevents:- os:bucket: cli-appid.cos.ap-beijing.myqcloud.comfilter:prefix: filterdir/suffix: .jpgevents: cos:ObjectCreated:*enable: false
在 f deploy 后,即可。
开发支持
针对 COS 触发器,我们提供了传入的事件类型定义。
import { SCF } from '@midwayjs/faas';import { Func } from '@midwayjs/decorator';export class CMQTriggerTest {@Func('cos.handler')async handler(event: SCF.COSEvent) {// TODO}}
本地开发
使用 f invoke 命令进行触发。
f invoke -f [你的函数名]
本地测试
这里没有传 data,会默认通过 f.yml 获取触发器类型传入模拟数据。
// testdescribe('/test/index.test.ts', () => {it('invoke', async () => {await invoke({functionName: 'cosTrigger',});});});
