加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 服务器 > 安全 > 正文

基于 Serverless +企业微信打造 nCoV 疫情监控小助手

发布时间:2020-05-11 05:23:06 所属栏目:安全 来源:站长网
导读:副标题#e# 最近的一些疫情信息很让人揪心,为了方便大家掌握疫情信息,在空闲之余做了一个关于 nCoV 的疫情监控小助手。主要的功能是通过企业微信的 WebHook 来推送疫情信息。这里将使用 Serverless 的整体代码思路和架构方式分享给大家。本文作者:tabor

那么我们接下了重点看下如何将我们的业务代码上传到云端呢?
这里的云端我用的是腾讯云 Serverless 服务 SCF云函数 。整个部署,使用过程都是免费的,对于开发者来讲小项目使用的话免费额度是完全够用的。无需担心额外付费。

Serverless 部署,选用的是比较流行的 Serverless Framework,使用和部署也是完全免费的,那么下面我就来介绍下具体的部署过程吧。

安装 Serverless 框架

首先,第一步,我们来安装一个 Serverless Framework 的开发框架:

$ npm install -g serverless

然后,我们创建一个函数目录:

$ mkdir nCov-function $ cd nCov-function

相关函数目录的内容如下:

|- code |- index.php // 这里就是上面的业务代码存放位置 |- serverless.yml //serverless 配置文件

配置 Yml 文件

接下来,是我们的重头戏,配置函数 yml 文件:

# serverless.yml myFunction: component: "@serverless/tencent-scf" //引用tencent-scf component inputs: name: nCoVFunction //函数名称 enableRoleAuth: true codeUri: ./code //代码本地存放位置 handler: index.main_handler runtime: Php5 region: ap-shanghai //函数运行地域 description: My Serverless nCoV Function. memorySize: 128 //运行内存 timeout: 20 //超时时间 exclude: - .gitignore - .git/** - node_modules/** - .serverless - .env include: - ./nCoVFunction.zip environment: variables: TEST: vale vpcConfig: subnetId: '' vpcId: '' events: - timer: // 定时触发器 name: timer parameters: cronExpression: '0 0 10,21 * * * *' //明天早上10点,晚上21点 enable: true

万事具备,我们就可以直接部署 SLS 了。

部署到云端

通过 sls 命令(serverless 的缩写)进行部署,并可以添加 –debug 参数查看部署过程中的信息:

taborchen$ sls --debug DEBUG ─ Resolving the template's static variables. DEBUG ─ Collecting components from the template. DEBUG ─ Downloading any NPM components found in the template. DEBUG ─ Analyzing the template's components dependencies. DEBUG ─ Creating the template's components graph. DEBUG ─ Syncing template state. DEBUG ─ Executing the template's components graph. DEBUG ─ Compressing function nCoVFunction file to /Users/taborchen/Desktop/工作/yiqing/.ser verless/nCoVFunction.zip. DEBUG ─ Compressed function nCoVFunction file successful DEBUG ─ Uploading service package to cos[sls-cloudfunction-ap-shanghai-code]. sls-cloudfunc tion-default-nCoVFunction-1580960644.zip DEBUG ─ Uploaded package successful /Users/taborchen/Desktop/工作/yiqing/.serverless/nCoVFu nction.zip DEBUG ─ Creating function nCoVFunction DEBUG ─ Created function nCoVFunction successful DEBUG ─ Setting tags for function nCoVFunction DEBUG ─ Creating trigger for function nCoVFunction DEBUG ─ Created timer trigger timer for function nCoVFunction success. DEBUG ─ Deployed function nCoVFunction successful

运行结果如下:

这样,我们就完成了一个 nCoV 的在线触发函数机器人~是不是很简单呢?快来开始动手吧~

传送门:

GitHub: github.com/serverless

官网:serverless.com

好了,就给大家介绍到这来,希望大家喜欢!

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读