- 浏览: 2566841 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
AMAZON and serverless(5)Lambda Invoke and Log
Logging
There is a logging package called debug
> npm info debug version
3.1.0
https://github.com/visionmedia/debug#readme
import debug from 'debug';
const logger = debug('acknowledgehandler');
const record = JSON.parse(parameters);
logger(record);
logger('Meeting creation succeeded');
Then we can configure the DEBUG=* to show all the logging, or configure DEBUG=acknowldegehandler to show only some logging.
Lambda Directly Invoke
import { APIGatewayEvent, Callback, Context } from 'aws-lambda';
const aws_region = process.env.AWS_REGION;
const lambda = new AWS.Lambda({ region: aws_region });
export async function invokeLambda(functionName: string, request: any) {
const params = {
FunctionName: functionName,
InvocationType: 'RequestResponse',
LogType: 'None',
Payload: JSON.stringify(request)
};
try {
console.log('invoking lambda: ', params);
const response = await lambda.invoke(params).promise();
if(!response) {
console.error(`failure getting result from ${functionName} lambda`)
throw new Error(`failure getting result from ${functionName} lambda`);
}
console.log('lambda response: ', response);
const responseObj = JSON.parse(response.Payload as string);
const statusCode = idx(responseObj, _ => _.statusCode);
const statusMessage = idx(responseObj, _ => _.statusMessage);
if(statusCode < 200 || 202 < statusCode) {
throw new Error(`Bad statusCode returnd by ${functionName} lambda: ${statusCode} - ${statusMessage}`);
}
return idx(responseObj, _ => _.body) || {};
} catch(err) {
throw err;
}
}
export async function getExtension() {
return await invokeLambda(get_extension_lambda, {});
}
TypeScript Validation
> npm info joi version
13.2.0
https://github.com/hapijs/joi
import Joi = require('joi’);
const meetingCreateSchema = Joi.object().keys({
displayName: Joi.string()
.min(1)
.optional(),
description: Joi.string()
.min(1)
.optional(),
pin: Joi.number()
.min(1)
.optional(),
moderatorExtension: Joi.number()
.min(1)
.optional(),
ownerExtension: Joi.number()
.min(1)
.optional(),
lecturerExtension: Joi.number()
.min(1)
.optional(),
tempMeeting: Joi.boolean()
.optional(),
hiddenMeeting: Joi.boolean()
.optional()
});
const meetingUpdateSchema = Joi.object().keys({
uuid: Joi.string()
.uuid({version: ['uuidv4']})
.required(),
displayName: Joi.string()
.min(1)
.optional(),
description: Joi.string()
.min(1)
.optional(),
pin: Joi.number()
.min(1)
.optional(),
moderatorExtension: Joi.number()
.min(1)
.optional(),
ownerExtension: Joi.number()
.min(1)
.optional(),
lecturerExtension: Joi.number()
.min(1)
.optional(),
tempMeeting: Joi.boolean()
.optional(),
hiddenMeeting: Joi.boolean()
.optional()
});
const meetingDeleteSchema = Joi.object().keys({
uuid: Joi.string()
.uuid({version: ['uuidv4']})
.required(),
});
const validationMapByOperation = {
'/meeting/create': meetingCreateSchema,
'/meeting/update': meetingUpdateSchema,
'/meeting/delete': meetingDeleteSchema
};
const schema = validationMapByOperation[uriSuffix];
const validationResult = Joi.validate(parameters, schema, {convert: true, allowUnknown: false});
if (validationResult.error) {
console.log('validation error: ', validationResult );
const errorMessage = idx(validationResult, _ => _.error.details[0].message); // returns the first validation error
return errorResponse(cb, 401, `${uriSuffix} : ${errorMessage}`);
}
References:
https://github.com/visionmedia/debug#readme
Logging
There is a logging package called debug
> npm info debug version
3.1.0
https://github.com/visionmedia/debug#readme
import debug from 'debug';
const logger = debug('acknowledgehandler');
const record = JSON.parse(parameters);
logger(record);
logger('Meeting creation succeeded');
Then we can configure the DEBUG=* to show all the logging, or configure DEBUG=acknowldegehandler to show only some logging.
Lambda Directly Invoke
import { APIGatewayEvent, Callback, Context } from 'aws-lambda';
const aws_region = process.env.AWS_REGION;
const lambda = new AWS.Lambda({ region: aws_region });
export async function invokeLambda(functionName: string, request: any) {
const params = {
FunctionName: functionName,
InvocationType: 'RequestResponse',
LogType: 'None',
Payload: JSON.stringify(request)
};
try {
console.log('invoking lambda: ', params);
const response = await lambda.invoke(params).promise();
if(!response) {
console.error(`failure getting result from ${functionName} lambda`)
throw new Error(`failure getting result from ${functionName} lambda`);
}
console.log('lambda response: ', response);
const responseObj = JSON.parse(response.Payload as string);
const statusCode = idx(responseObj, _ => _.statusCode);
const statusMessage = idx(responseObj, _ => _.statusMessage);
if(statusCode < 200 || 202 < statusCode) {
throw new Error(`Bad statusCode returnd by ${functionName} lambda: ${statusCode} - ${statusMessage}`);
}
return idx(responseObj, _ => _.body) || {};
} catch(err) {
throw err;
}
}
export async function getExtension() {
return await invokeLambda(get_extension_lambda, {});
}
TypeScript Validation
> npm info joi version
13.2.0
https://github.com/hapijs/joi
import Joi = require('joi’);
const meetingCreateSchema = Joi.object().keys({
displayName: Joi.string()
.min(1)
.optional(),
description: Joi.string()
.min(1)
.optional(),
pin: Joi.number()
.min(1)
.optional(),
moderatorExtension: Joi.number()
.min(1)
.optional(),
ownerExtension: Joi.number()
.min(1)
.optional(),
lecturerExtension: Joi.number()
.min(1)
.optional(),
tempMeeting: Joi.boolean()
.optional(),
hiddenMeeting: Joi.boolean()
.optional()
});
const meetingUpdateSchema = Joi.object().keys({
uuid: Joi.string()
.uuid({version: ['uuidv4']})
.required(),
displayName: Joi.string()
.min(1)
.optional(),
description: Joi.string()
.min(1)
.optional(),
pin: Joi.number()
.min(1)
.optional(),
moderatorExtension: Joi.number()
.min(1)
.optional(),
ownerExtension: Joi.number()
.min(1)
.optional(),
lecturerExtension: Joi.number()
.min(1)
.optional(),
tempMeeting: Joi.boolean()
.optional(),
hiddenMeeting: Joi.boolean()
.optional()
});
const meetingDeleteSchema = Joi.object().keys({
uuid: Joi.string()
.uuid({version: ['uuidv4']})
.required(),
});
const validationMapByOperation = {
'/meeting/create': meetingCreateSchema,
'/meeting/update': meetingUpdateSchema,
'/meeting/delete': meetingDeleteSchema
};
const schema = validationMapByOperation[uriSuffix];
const validationResult = Joi.validate(parameters, schema, {convert: true, allowUnknown: false});
if (validationResult.error) {
console.log('validation error: ', validationResult );
const errorMessage = idx(validationResult, _ => _.error.details[0].message); // returns the first validation error
return errorResponse(cb, 401, `${uriSuffix} : ${errorMessage}`);
}
References:
https://github.com/visionmedia/debug#readme
发表评论
-
Stop Update Here
2020-04-28 09:00 331I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 491NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 377Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 381Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 351Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 439Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 449Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 392Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 475VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 401Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 496NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 438Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 346Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 262GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 463GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 336GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 322Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 330Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 306Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 320Serverless with NodeJS and Tenc ...
相关推荐
【标题】"java-dagger2-serverless-lambda:使用匕首的AWS Lambda Java Serverless" 涉及到的关键技术是Java开发、Dagger 2依赖注入框架以及AWS Lambda无服务器计算平台。这个项目旨在展示如何将Dagger 2集成到一个...
这是一个使用Serverless框架在AWS Lambda上运行Chromepuppeteer的演示。 要使其在本地无服务器脱机环境中运行 yarn install yarn serverless 它将在 要部署到您的AWS环境,你需要让你的AWS帐户存储的凭据正确,即...
AWS Lambda是亚马逊Web服务(AWS)提供的一个核心Serverless计算服务,它允许开发者运行代码而无需预先配置或管理服务器。本篇文章将深入探讨Serverless架构的概念、优势、工作原理以及AWS Lambda的具体应用。 一、...
【标题】"serverless-lambda-starter-kit" 是一个针对使用无服务器架构的开发者设计的入门工具包,特别关注于AWS Lambda服务与无服务器框架的集成。它旨在简化使用Node.js 8.10版本在Lambda上运行应用程序的流程。 ...
The first module explains the fundamentals of serverless architecture and how AWS lambda functions work. In the next module, you will learn to build, release, and deploy your application to ...
$ npm install --save-dev serverless-lambda-edge-pre-existing-cloudfront 这个怎么运作 配置serverless.yml functions : viewerRequest : handler : lambdaEdge/viewerRequest.handler events : - ...
pfs-电子邮件-无服务器 这是由无服务器框架创建的lambda函数。 它会在我们的mongodb中搜索尚未收到电子邮件的成员,并向他们发送包含自定义令牌的电子邮件,以解锁免费... serverless invoke --function sendEmails -
Serverless Architectures with AWS begins with an introduction to the serverless model and helps you get started with AWS and AWS Lambda....serverless applications with and without Lambda.
45-段佳昂-(2021 ASPLOS)Nightcore efficient and scalable serverless Nightcore 是一种高效、可扩展的服务器less 计算平台,旨在满足延迟敏感型交互微服务的严格延迟目标。当前的服务器less 平台存在毫秒级的...
This book will focus on AWS Lambda from the viewpoint of an AWS user who has not yet used the service.
无服务器lambda-pdfkit 安装依赖项 yarn install离线运行本地 yarn serverless建立图层 pushd layer && yarn --cwd nodejs && zip -9r pdfkit-layer.zip nodejs && popd更改serverless.yml profile以使用您的AWS配置...
Serverless Design Patterns and Best Practices: Build, secure, and deploy enterprise ready serverless applications with AWS to improve developer productivity
And thanks to JavaScript support in AWS Lambda and powerful new serverless API tools like the Claudia.js library, you can build and deploy serverless apps end to end without learning a new language. ...
《Serverless架构:无服务器应用与AWS Lambda》的作者Peter Sbarski 是最早完全拥抱无服务器架构的开发者之一,他将自己在应用无服务器架构中获得的宝贵经验总结成本书,呈现给广大的读者。更难能可贵的是,全书贯穿...
无服务器Lambda SNS示例流程示例: Lambda(发布者)=> SNS => Lambda(消费者)设置安装Node 8.10(AWS Lambda支持的最新运行时) 安装无服务器(已针对无服务器v1.28.0进行了测试) $ npm i -g serverless安装节点...
serverless plugin install --name serverless-layers 将插件添加到您的serverless.yml文件中: 单层配置 例: plugins : - serverless-layers custom : serverless-layers : functions : # optional - my_...
Serverless Web Applications with React and Firebase 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书