aws lambda

by Yan Cui

崔燕

如何为AWS Lambda实施日志聚合 (How to implement log aggregation for AWS Lambda)

Dur­ing the exe­cu­tion of a Lamb­da func­tion, what­ev­er you write to std­out (for example, using console.log in Node.js) will be cap­tured by Lamb­da and sent to Cloud­Watch Logs asyn­chro­nous­ly in the back­ground. And it does this with­out adding any over­head to your func­tion exe­cu­tion time.

在执行Lambda函数期间,您写入stdout的任何内容(例如,使用Node.js中的console.log )都会被Lambda捕获,并在后台异步发送到CloudWatch Logs。 这样做不会增加函数执行时间的开销。

You can find all the logs for your Lamb­da func­tions in Cloud­Watch Logs. There is a unique log group for each func­tion. Each log group then consists of many log streams, one for each concurrently executing instance of the function.

您可以在CloudWatch Logs中找到Lambda函数的所有日志。 每个功能都有一个唯一的日志组。 每个日志组则由许多日志流组成,每个并发执行该功能的实例一个。

You can send logs to Cloud­Watch Logs your­self via the Put­Lo­gEvents oper­a­tion. Or you can send them to your pre­ferred log aggre­ga­tion ser­vice such as Splunk or Elas­tic­search.

您可以自己通过PutLogEvents操作将日志发送到CloudWatch Logs。 或者,您可以将它们发送到首选的日志聚合服务,例如Splunk或Elasticsearch。

But, remem­ber that every­thing has to be done dur­ing a function’s invocation. If you make addi­tion­al net­work calls dur­ing the invo­ca­tion, then you’ll pay for that addi­tion­al exe­cu­tion time. Your users would also have to wait longer for the API to respond.

但是,请记住, 在函数调用期间必须完成所有操作 。 如果您在调用期间进行了其他网络调用,则需要为该额外的执行时间付费。 您的用户还必须等待更长的时间才能使API响应。

These extra network calls might only add 10–20ms per invocation. But you have microservices, and a single user action can involve several API calls. Those 10–20ms per API call can compound and add over 100ms to your user-facing latency, which is enough to reduce sales by 1% according to Amazon.

这些额外的网络调用每次调用可能只会增加10–20ms。 但是您拥有微服务,单个用户操作可能涉及多个API调用。 根据Amazon的说法,每个API调用需要10-20毫秒的时间,这会使您面对用户的延迟加重并增加100毫秒以上,这足以使销售量减少1% 。

So, don’t do that!

所以,不要那样做!

Instead, process the logs from Cloud­Watch Logs after the fact.

相反,请在事实之后处理CloudWatch Logs中的日志。

In the Cloud­Watch Logs con­sole, you can select a log group and choose to stream the data direct­ly to Amazon’s host­ed Elas­tic­search ser­vice.

在CloudWatch Logs控制台中,您可以选择一个日志组,然后选择将数据直接流式传输到Amazon托管的Elasticsearch服务。

This is very use­ful if you’re using the host­ed Elas­tic­search ser­vice already. But if you’re still eval­u­at­ing your options, then give this post a read before you decide on the AWS-host­ed Elas­tic­search.

如果您已经在使用托管的Elasticsearch服务,这将非常有用。 但是,如果您仍在评估选项,则在决定由AWS托管的Elasticsearch之前,请阅读此文章 。

You can also stream the logs to a Lamb­da func­tion instead. There are even a num­ber of Lambda function blue­prints for push­ing Cloud­Watch Logs to oth­er log aggre­ga­tion ser­vices already.

您也可以将日志流传输到Lambda函数。 甚至还有许多Lambda功能蓝图,用于将CloudWatch Logs推送到其他日志聚合服务。

Clear­ly this is some­thing a lot of AWS’s cus­tomers have asked for.

显然,这是许多AWS客户所要求的。

You can use these blue­prints to help you write a Lamb­da func­tion that’ll ship Cloud­Watch Logs to your pre­ferred log aggre­ga­tion ser­vice. But here are a few more things to keep in mind.

您可以使用这些蓝图来帮助您编写Lambda函数,该函数会将CloudWatch Logs运送到您首选的日志聚合服务。 但是,还有几件事要牢记。

When­ev­er you cre­ate a new Lamb­da func­tion, it’ll cre­ate a new log group in Cloud­Watch logs. You want to avoid a man­u­al process for sub­scrib­ing log groups to your log shipping func­tion.

每当您创建新的Lambda函数时,它将在CloudWatch日志中创建一个新的日志组。 您希望避免手动将日志组订阅到日志传送功能的过程。

Instead, enable Cloud­Trail, and then set­up an event pat­tern in Cloud­Watch Events to invoke anoth­er Lamb­da func­tion when­ev­er a log group is cre­at­ed.

相反,启用CloudTrail,然后在CloudWatch Events中设置事件模式以在创建日志组时调用另一个Lambda函数。

You can do this one-off set­up in the Cloud­Watch con­sole.

您可以在CloudWatch控制台中进行一次性设置。

If you’re work­ing with mul­ti­ple AWS accounts, then you should avoid mak­ing the set­up a man­u­al process. With the Server­less frame­work, you can set­up the event source for this subscribe-log-group func­tion in the serverless.yml.

如果您使用多个AWS账户,则应避免手动进行设置。 使用Serverless框架,您可以在serverless.yml中为该serverless.yml subscribe-log-group函数设置事件源。

Anoth­er thing to keep in mind is that you need to avoid sub­scrib­ing the log group for the ship-logs func­tion to itself. It’ll cre­ate an infi­nite invo­ca­tion loop and that’s a painful les­son that you want to avoid.

要记住的另一件事是, 您需要避免 为自身 ship-logs 功能 订阅日志组 这将创建一个无限循环调用 ,这就是要避免一个惨痛的教训。

One more thing.

还有一件事。

By default, when Lamb­da cre­ates a new log group for your func­tion, the retention pol­i­cy is set to Never Expire. This is overkill, as the data storage cost can add up over time. It’s also unnecessary if you’re shipping the logs elsewhere already!

默认情况下,当Lambda为您的功能创建新的日志组时,保留策略将设置为Never Expire 。 这太过分了,因为随着时间的推移, 数据存储成本可能会增加。 如果您已经将日志发送到其他地方,则也没有必要!

We can apply the same tech­nique above and add anoth­er Lamb­da func­tion to automatically update the reten­tion pol­i­cy to some­thing more rea­son­able.

我们可以应用上面相同的技术,并添加另一个Lambda函数以将保留策略自动更新为更合理的方法。

If you already have lots of exist­ing log groups, then con­sid­er writing one-off scripts to update them all. You can do this by recurs­ing through all log groups with the DescribeL­og­Groups API call.

如果您已经有很多现有的日志组,请考虑编写一次性脚本来更新它们。 你可以做到这一点递归通过与所有的日志组DescribeLogGroups API调用。

If you’re interested in applying these techniques yourself, I have put together a simple demo project for you. If you follow the instructions in the README and deploy the functions, then all the logs for your Lambda functions would be delivered to Logz.io.

如果您有兴趣亲自应用这些技术,那么我为您准备了一个简单的演示项目 。 如果您按照自述文件中的说明进行操作并部署这些功能,则Lambda函数的所有日志都将传递到Logz.io。

翻译自: https://www.freecodecamp.org/news/how-to-implement-log-aggregation-for-aws-lambda-ca714bf02f48/

aws lambda

aws lambda_如何为AWS Lambda实施日志聚合相关推荐

  1. java log日志函数_Java 中的 AWS Lambda 函数日志记录 - AWS Lambda

    AWS 文档中描述的 AWS 服务或功能可能因区域而异.要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门. 本文属于机器翻译版本.若本译文内容与英语原文存在差异,则一律以英文原文为准. Ja ...

  2. aws lambda_在AWS Lambda上进行无服务器我的线性回归api

    aws lambda About a year ago, I had a fun idea for a small side project. I wanted to build an API to ...

  3. aws lambda_在AWS Lambda上运行“ Hello World”

    aws lambda Let's run the "Hello World" example on AWS Lambda. I would recommend reading ab ...

  4. AWS API Gateway与AWS Lambda代理集成构建REST API

    项目地址 https://github.com/JessicaWin/aws lambda分支为自动创建API Gateway REST API资源的部署方式 apigateway分支为自定义API ...

  5. aws cloud map_Amazon EC2 – AWS Elastic Compute Cloud

    aws cloud map Amazon EC2 is an abbreviation for Elastic Compute Cloud. It's elastic in nature which ...

  6. ASWEET项目实施日志

    写在前面 在写之前我们确实也在各大网站及平台上进行过搜索,也的确有很多项目总结或者是阶段性的项目记录,但没有日志型项目记录.更不用说是关于NetSuite这种SaaS ERP类型的实施日志了. 为什么 ...

  7. 云管理服务AWS Organizations正式在AWS中国区域上线

    近期, AWS中国(宁夏)区域(由西云数据运营)和AWS中国(北京)区域(由光环新网运营)正式上线了云管理服务AWS Organizations. 作为一种管理服务,AWS Organizations ...

  8. NetSuite实施日志-万字文

    感谢Vicky花费了近一个月时间来作此文,记录项目团队一起走过的路,留下的印记.我还是相信那句老话,"功不唐捐,玉汝于成!" 首先讲一下为啥要写这篇文字. 下面这张图是梅奥诊所的L ...

  9. 使用Lambda优化日志案例

    体验Lambda的更优写法 使用Lambda必然需要一个函数式接口: package com.learn.demo02.Lambda;@FunctionalInterface public inter ...

最新文章

  1. ASP.NET 配置节架构
  2. 普林斯顿三大读本,学数学必入!
  3. Spring编程式和声明式事务实例讲解
  4. python安装某些库失败的问题解决方案
  5. MySQL的基本查询(一)
  6. bootstrap .col-md-6 文字居中问题处理
  7. thinkphp5运行原理_ThinkPHP5.1~5.2全版本远程代码执行高危漏洞预警
  8. 【系统架构设计师】软考高级职称,一次通过,倾尽所有,2016年下半年系统架构设计师考试论文真题(论微服务架构及其应用)
  9. 06jQuery-06-AJAX
  10. 如何在 Linux 上重命名一组文件
  11. idea tomcat配置
  12. 《微服务设计》(一)---- 微服务
  13. numpy将所有数据变为0和1_PyTorch 学习笔记(二):张量、变量、数据集的读取、模组、优化、模型的保存和加载...
  14. 拓端tecdat|用SPSS估计HLM多层(层次)线性模型
  15. LayaAir graphics 矢量绘图之 圆形与扇形
  16. AStar算法通用实现+可视化(Matlab)
  17. wav怎么转换成mp3?
  18. html5全栈工程师招聘,蓝鸥HTML5全栈工程师 高薪就业的利器
  19. java拦截通过url访问页面,必须通过登录页面访问目标页面
  20. Suzy找到实习了吗Day25 | 回溯算法进行时:216. 组合总和 III,17电话号码

热门文章

  1. jsp+js实现二级级联
  2. 对于‘敲什么都队’自主开发的《校园服务》软件的使用体验
  3. hdu 1023 Train Problem II
  4. IOS开发之页面切换
  5. PHP实现单击“添加”按钮增加一行表单项,并将所有内容插入到数据库中
  6. ASP.NET 2.0 之 Master Page 学习笔记
  7. linux安装mysql 5.6.33
  8. Eclipse 插件开发 向导
  9. 简介DOTNET 编译原理 简介DOTNET 编译原理 简介DOTNET 编译原理
  10. POJ - 3257 Cow Roller Coaster (背包)