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.pswp.cn/news/395343.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395343.shtml
英文地址,請注明出處:http://en.pswp.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