Query log from aws lambda with aws cloudwatch log insight

--

หาว่า request ไหนมันใช้เวลาในการทำงานนานๆ ถ้าทำงานนานๆ มันก็เเพงดิค๊าบบ

filter @type = “REPORT”

| fields @requestId, @billedDuration

| sort by @billedDuration desc

เอา request id ที่ได้ ไป query เพิ่มเติมเพื่อหารายละเอียดอื่นๆ

fields @timestamp, @message

| filter @message like /reuest-id-xxxx-xxxx-uuid/

| sort @timestamp desc

| limit 20

หาว่า lambda function นั้นๆ มันคิดเงินไปเท่าไร ถูกเรียกใช้ไปกี่ครั้ง

filter @type = "REPORT"
| stats
count(@type) as countInvocations ,
sum(@billedDuration) / 1000 as allDurationInSeconds,
max(@memorySize) / 1024 / 1024 / 1024 as memoryAllocated,
allDurationInSeconds * memoryAllocated * 0.0000166667 as totalCost,
totalCost / countInvocations as avgCostPerInvocation

อันนี้ Ref : https://stackoverflow.com/questions/69923628/how-to-find-the-lambda-function-that-costs-the-most-money

--

--