aws lambda_如何为AWS Lambda实施日志聚合

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/395343.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Python3爬虫】为什么你的博客没人看呢?

我相信对于很多爱好和习惯写博客的人来说,如果自己的博客有很多人阅读和评论的话,自己会非常开心,但是你发现自己用心写的博客却没什么人看,多多少少会觉得有些伤心吧?我们今天就来看一下为什么你的博客没人看呢&#…

泰安高考2021成绩查询,泰安高考成绩查询入口2021

高考结束之后,为了方便大家进行高考成绩的查询,下面跟着出国留学网小编来一起看看“泰安高考成绩查询入口2021”,仅供参考,希望对大家有帮助。2021山东高考成绩查询时间及志愿填报时间根据山东2021年夏季高考须知,2021…

用GitHub Issue取代多说,是不是很厉害?

2019独角兽企业重金招聘Python工程师标准>>> 摘要: 别了,多说,拥抱Gitment。 2017年6月1日,多说正式下线,这多少让人感觉有些遗憾。在比较了多个博客评论系统,我最终选择了Gitment作为本站的博客评论系统&a…

mysql延时优化教程_Mysql优化之延迟索引和分页优化_MySQL

什么是延迟索引?使用索引查询出来数据,之后把查询结果和同一张表中数据进行连接查询,进而提高查询速度!分页是一个很常见功能,select ** from tableName limit ($page - 1 ) * $n ,$n通过一个存储过程插入10000条数据进行测试&…

【动态规划】Vijos P1313 金明的预算方案(NOIP2006提高组第二题)

题目链接&#xff1a; https://vijos.org/p/1313 题目大意&#xff1a; m(m<32000)金钱&#xff0c;n&#xff08;n<60&#xff09;个物品&#xff0c;花费vi&#xff0c;价值vi*ci,每个物品可能有不超过2个附件&#xff0c;附件没有附件。 题目思路&#xff1a; 【动态规…

计算机网络应用答题卡,2013-2014学年第2学期11级计算机网络技术毕业考试试卷

2013-2014学年第2学期11级《计算机网络技术》课程毕业考试试卷得分&#xff1a;一、单项选择题&#xff1a;(每题1分&#xff0c;共30分&#xff0c;答案必须写在后面的选择题答题卡内&#xff0c;否则不得分)1、计算机网络可以按网络的覆盖范围来划分&#xff0c;以下()不是按…

0622 - 如何坚守自己的价值观?

如果有人有着和自己迥异的价值观&#xff0c;且混得很好&#xff0c;且和自己是熟人&#xff0c;自己是不是要改变自己、向其学习&#xff1f; 比如&#xff0c;常说的「学习好的比学习差的打工」&#xff0c;那到底是要好好学习&#xff0c;还是提前混人脉、攒经验&#xff1f…

如何免费注册Coursera课程

One question I get asked all the time here at Class Central is: are Coursera courses really free?在班级中心&#xff0c;我一直被问到的一个问题是&#xff1a; Coursera课程真的免费吗&#xff1f; Coursera’s user interface is intentionally designed to push le…

三态门有一个信号控制端en_三态门verilog

双向口-三态门的电路IC专业技术文章2008-12-06 14:59:24阅读119评论0字号&#xff1a;大中小订阅1.TTL三态门电路工作原理:三态门电路的基本结构如下图所示&#xff1a;(1)图1给出了三态门的电路结构图及图形符号。其中控制端EN为低电平时,P点为高电平&#xff0c;二极管D截止&…

[树形dp] Jzoj P3914 人品问题

Description 网上出现了一种高科技产品——人品测试器。只要你把你的真实姓名输入进去&#xff0c;系统将自动输出你的人品指数。yzx不相信自己的人品为0。经过了许多研究后&#xff0c;yzx得出了一个更为科学的人品计算方法。这种方法的理论依据是一个非常重要的结论&#xff…

为什么那些每三年跳一次槽的人越跳越好? - 震撼

现在&#xff0c;人们已经放下了对跳槽的偏见。这是一件好事。之前。假设你每几年换一次工作&#xff0c;人们会认为你的简历上有 “污点”。面试官会认为你无法胜任一份工作。与同事相处不好。或者你对公司不忠诚&#xff0c;不能承担任务&#xff0c;等等。 这样的想法非常快…

2019 6月编程语言_六月开始提供435项免费在线编程和计算机科学课程

2019 6月编程语言Five years ago, universities like MIT and Stanford first opened up free online courses to the public. Today, more than 700 schools around the world have created thousands of free online courses.五年前&#xff0c;麻省理工学院和斯坦福大学等大…

使用html记笔记,开始学习HTML,并记下笔记

开始学习HTML,并记下笔记。外边距(不影响可见框大小&#xff0c;影像盒子位置)margin-top(上)right(右)bottom(下)left(左)“外边距也可以为一个负值&#xff0c;元素会反方向移动”margin还可以设置为auto&#xff0c;auto一般只设置给水平方向的margin.如果只指定&#xff0c…

矢量合成和分解的法则_专题14 运动的合成与分解

运动的合成与分解【基础回顾】 考点内容:运动的合成与分解 考纲解读: 1.掌握曲线运动的概念、特点及条件. 2.掌握运动的合成与分解法则&#xff0e; 考点一 物体做曲线运动的条件及轨迹分析 1&#xff0e;条件  (1)因为速度时刻在变&#xff0c;所以一定存在加速度&#xff1…

详解--单调队列 经典滑动窗口问题

单调队列&#xff0c;即单调的队列。使用频率不高&#xff0c;但在有些程序中会有非同寻常的作用。 动态规划单调队列的理解 做动态规划时常常会见到形如这样的转移方程&#xff1a;f[x] max or min{g(k) | b[x] < k < x} w[x](其中b[x]随x单调不降&#xff0c;即b[1]&…

Java Persistence with MyBatis 小结2

MyBatis 最关键的组成部分是 SqlSessionFactory&#xff0c;我们可以从中获取 SqlSession&#xff0c;并执行映射的 SQL 语句。SqlSessionFactory 对象可以通过基于 XML 的配置信息或者 Java API 创建。 1 mybatis环境&#xff0c;environments 配置默认的数据库环境 MyBatis 支…

《计算机应用基础》18春作业,【北语网院】18春《计算机应用基础》作业_2.pdf...

谋学网【北京语言大学】 18 春《计算机应用基础》作业 _2试卷总分 :100 得分 :100第 1 题, 操作系统是 ___ 的接口。A、用户与软件B、系统软件与应用软件C、主机与外设D、用户与计算机第 2 题, 计算机配置的内存的容量为 128MB或 128MB以上&#xff0c;其中的 128MB是指 __ 。A…

freeCodeCamp纳什维尔十月聚会回顾

by Seth Alexander塞斯亚历山大(Seth Alexander) 纳什维尔的美好时光&#xff1a;十月免费CodeCamp聚会的回顾 (Good times in Nashville: a recap of our October freeCodeCamp Meetup) On Saturday, October 7, we had our monthly freeCodeCamp Nashville meetup at Nashvi…

c#时分秒毫秒微妙_你真的清楚DateTime in C#吗?

DateTime&#xff0c;就是一个世界的大融合。日期和时间&#xff0c;在我们开发中非常重要。DateTime在C#中&#xff0c;专门用来表达和处理日期和时间。本文算是多年使用DateTime的一个总结&#xff0c;包括DateTime对象的整体应用&#xff0c;以及如何处理不同的区域、时区、…

(HY000): Cannot modify @@session.sql_log_bin inside a transaction

昨天&#xff0c;线上发生一例(HY000): Cannot modify session.sql_log_bin inside a transaction代码缺少显示的start transaction控制。。转载于:https://www.cnblogs.com/zhjh256/p/5775390.html