Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running with Plugins
My serverless.yml will be changed as follow:
service: orderinfo
provider:
name: tencent
region: ap-shanghai
runtime: Nodejs8.9
credentials: ~/.credentials.ini
stage: prod
memorySize: 128
timeout: 60
plugins:
- serverless-tencent-scf
package:
excludeDevDependencies: false
exclude:
- .gitignore
- .git/**
- .serverless
- .env
- app.js
- .DS_Stone
functions:
order-manager:
handler: handler.orderManager
description: Task Manager to Fetch Tasks
memorySize: 128
timeout: 60
events:
# 以下是各触发器配置示例
# - timer:
# name: test
# cron: "*/5 * * * *"
- apigw:
name: order-manager_apigw
parameters:
stageName: release
serviceId: service-mxgirfqn
httpMethod: GET
order-runner:
handler: handler.ordeRunner
description: Task Runner to Calculate
events:
- apigw:
name: order-runner_apigw
parameters:
stageName: release
serviceId: service-4qn5efd1
httpMethod: GET
My handler.js will be as follow:
'use strict';
const {OrderService} = require('./src/service');
const {DB} = require('async-mysql-wrapper');
const _ = require('lodash');
exports.orderManager = async (event, context, callback) => {
console.log("orderManager, event:" + JSON.stringify(event));
DB.init({
dbConnectionConfig: {
host: process.env.MYSQL_DB_ADDRESS,
user: process.env.MYSQL_DB_USER,
database: process.env.MYSQL_DB_NAME,
password: process.env.MYSQL_DB_PASSWORD,
connectionLimit: process.env.MYSQL_DB_POOL_SIZE || 2,
waitForConnections: true,
dateStrings: true,
},
logLevel: 'debug'
});
await OrderService.groupLoadOrderInfo();
return "success";
};
exports.ordeRunner = async (event, context, callback) => {
const msg = _.get(event, 'message') || _.get(JSON.parse(_.get(event, 'body')), 'message');
console.log("ordeRunner, message:" + msg);
DB.init({
dbConnectionConfig: {
host: process.env.MYSQL_DB_ADDRESS,
user: process.env.MYSQL_DB_USER,
database: process.env.MYSQL_DB_NAME,
password: process.env.MYSQL_DB_PASSWORD,
connectionLimit: process.env.MYSQL_DB_POOL_SIZE || 2,
waitForConnections: true,
dateStrings: true,
},
logLevel: 'debug'
});
await OrderService.calculateAllOrderInfo(msg);
return "success";
};
References:
https://github.com/tencentyun/serverless-tencent-scf/blob/master/example/serverless.yml
分享到:
相关推荐
描述在五分钟或更短的时间内引导一个新的Node.js Serverless项目。特征使用在下部署到 。 的包结构。 使用快速,可靠和安全的依赖项管理。 带有可配置选项和参数的示例,这些示例和参数由提供。 使用使用进行。 代码...
Serverless Design Patterns and Best Practices: Build, secure, and deploy enterprise ready serverless applications with AWS to improve developer productivity
《Python库 TencentCloud SDK Python详解》 在Python的开发中,使用第三方库可以极大地提高我们的工作效率,TencentCloud SDK Python便是这样一个重要的工具。这个库专为Python开发者设计,旨在简化与腾讯云服务的...
Serverless Web Applications with React and Firebase 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
用法Docker运行命令 # running Serverless version 1.72.0$ docker run --rm amaysim/serverless:1.72.0 serverless --help在本地构建图像如果您要构建和使用自己的本地映像 # build image locally with latest ...
serverless-nodejs-starter 具有Webpack,自定义域和单元测试支持的无服务器框架的Node.js入门 安装后,您可以在几分钟之内创建和部署具有最新ES6功能的功能,并加入棉绒和格式。 使用插件和 。 它支持: 处理...
The benefits of cloud-hosted serverless web apps are undeniable: lower complexity, quicker time to market, and easier scalability than traditional, server-dependent designs. And thanks to JavaScript ...
paced journey through building real-time applications with Firebase features such as Cloud Storage, Cloud Function, Hosting and the Realtime Database. We will learn how to secure our application by ...
Serverless Architectures with AWS begins with an introduction to the serverless model and helps you get started with AWS and AWS Lambda. You'll also get to grips with other capabilities of the AWS ...
Serverless Application with Nodes.js 全英文 2019出版 Serverless Applications with Node.js walks you through building serverless apps on AWS using JavaScript. Inside, you’ll discover what Claudia.js ...
Serverless computing with Azure and .NET 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
在本地运行API网关使用serverless offline start 支持单元测试运行npm test以运行测试 正确错误消息的源映射 错误消息显示正确的行号 使用CloudWatch进行生产 使用ESLint整理代码 为您的阶段添加环境变量 无需管理...
《Python库 Tencentcloud-sdk-python-tsf 3.0.435详解》 在Python的开发环境中,Tencentcloud-sdk-python-tsf库扮演着至关重要的角色。它为开发者提供了与腾讯云TSF(Tencent Serverless Framework)进行交互的工具...
《Python库 Tencentcloud-sdk-python-tsw详解》 在IT领域,Python因其简洁、高效和丰富的库支持而备受青睐。本文将深入探讨一个特定的Python库——Tencentcloud-sdk-python-tsw,它是一个针对腾讯云服务的SDK,版本...
You will also learn to troubleshoot and monitor your app and master AWS lambda programming concepts with API references. Moving on, you will also learn how to scale up serverless applications and ...