SlideShare a Scribd company logo
1 of 25
Download to read offline
CloudWatch hidden features for
debugging serverless application
Marko (ServerlessLife)
Full-stack Software Developer | AWS Certified Professional |
Serverless Specialist
Blog: www.serverlesslife.com
Email: marko@serverlesslife.com
Twitter: @ServerlessL
LinkedIn: https://www.linkedin.com/in/marko-serverlesslife/
CloudWatch
Set of AWS services for observability.
Observability
Umbrella term for:
● Logging
● Metrics
● Tracing
Why is it important?
Complex serverless applications look like this:
Source: https://dzone.com/articles/observability-driven-development-for-serverless
Debugging serverless / microservices?
Source:
https://play.google.com/store/apps/details?id=com.
apsocialsoft.murdermystery&hl=en_US&gl=US
CloudWatch vs. 3rd party
+ quite powerful
+ it is already there, no issues with sharing the data
- user / developer experience 👎👎👎👎👎
3rd party tools/services:
Try to use services specialized for serverless: Lumigo, Epsagon, Thundra
Lambda and CloudWatch logs
Log groups ➡ multiple log stream
Node.js libraries:
● https://www.npmjs.com/package/lambda-log
● https://github.com/middyjs/middy + error-logger/input-output-logger
● https://awslabs.github.io/aws-lambda-powertools-typescript/ (BETA !!!)
⚠Warning: CloudWatch is expensive 💸💸💸💸💸
CloudWatch is usually more expensive than Lambda.
Solutions:
● Do not log too much.
● Limit retention.
● Use sampling.
● Log request and other details only in case of an error.
● Enable detailed logging only when needed.
Logs Insights
● Takes about 1 min to update.
● Query language is extremely powerful.
● You can use regular expressions and parse the message.
● You can store the query (also with IaC).
● There are already prepared queries.
Logs Insights sample
Errors in Lambda:
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
Logs Insights sample
Poor man distributed tracer:
console.log("MY DATA", JSON.stringify({
orderId: 1234,
customerName: 'John Smith',
traceIds: ['b4346', 'fd418']
}));
fields @timestamp, @message
| filter @message like /b4346/
| sort @timestamp desc
Logs Insights sample
Parse string:
console.log('userId:4567,city:London');
fields @timestamp, @message
| parse @message /^.*userId:(?<userId>d*),city
:(?<city>.*)$/
| filter userId = 4567
| display userId, city, @message
| sort @timestamp desc
Logs Insights sample
Average duration, max duration, min duration, P99 percentile duration and request
count:
filter @type = "REPORT"
| stats avg(@duration), max(@duration), min(@duration), pct(@duration, 99),
count(@duration) by bin(5m)
Credit: https://dev.to/aws-heroes/10-cloudwatch-logs-insights-examples-for-serverless-applications-4293
Logs Insights sample
Number of exceptions per 5-minute intervals:
filter @message like /ERROR/
| stats count(*) as exceptionCount by bin(5m)
| sort exceptionCount desc
Logs Insights sample
Count a number of cold starts, average init time and maximum init duration of a
Lambda function
filter @type="REPORT"
| fields @memorySize / 1000000 as memorySize
| filter @message like /(?i)(Init Duration)/
| parse @message /^REPORT.*Init Duration: (?<initDuration>.*) ms.*/
| parse @log /^.*/aws/lambda/(?<functionName>.*)/
| stats count() as coldStarts, avg(initDuration) as avgInitDuration,
max(initDuration) as maxIntDuration by functionName, memorySize
Logs Insights sample
Lambda cold start percentage over time
filter @type = "REPORT"
| stats
sum(strcontains(
@message,
"Init Duration"))
/ count(*)
* 100
as coldStartPercentage,
avg(@duration)
by bin(5m)
Credit: https://github.com/julianwood/serverless-cloudwatch-logs-insights-examples
API Gateway
The Missing Guide to AWS API Gateway Access Logs
https://www.alexdebrie.com/posts/api-gateway-access-logs/
Metrics
Data is kept for 15 months.
Math expressions
Metrics Insights (SQL Query) - only last 3h
Types of Metrics
● Build in
● Custom
○ Synchronously
○ Asynchronously:
■ Log something ➡ create filter to transform to metric
■ Embedded Metric Format:
Log in specific format ➡ auto-transformed to metrics
Alarms
What alerts should you have for serverless applications?
https://lumigo.io/blog/what-alerts-should-you-have-for-serverless-applications/
⚠ Alarm fatigue
The high number of false alarms become senseless background noise.
Composite Alarms - goes into ALARM state only if all conditions of the rule are met
Tracing with X-Ray
Stores trace data for the last 30 days.
How to enable:
● Enable on API Gateway & Lambda
● Add:
const AWSXRay = require('aws-xray-sdk-core')
const AWS = AWSXRay.captureAWS(require('aws-sdk'))
● Additional configuration for SQS,
Use segments, annotation and metadata to add additional information.
Additional use for segments:
● Lambda doesn’t allow us to add custom annotations and metadata to its root segment.
This can be resolved by custom subsegment.
● When calling 3rd party service.
Sample app
Insights (do not mix with Logs Insights)
● Lambda Insights
● Contributor Insights ➡ DynamoDB
● …
Dashboard
● Automatic dashboards
● Sharing
● Custom Widgets
Create a Lambda that return static HTML. JavaScript is not allowed. Can be dynamic
with using special tags.
Anomaly Detection
It trains on up to two weeks of metric data.
Thank you!
Don’t be a stranger:
Email: marko@serverlesslife.com
Blog: www.serverlesslife.com
Twitter: @ServerlessL
LinkedIn: https://www.linkedin.com/in/marko-serverlesslife/

More Related Content

Similar to CloudWatch hidden features for debugging serverless apps

Serverless Development Deep Dive
Serverless Development Deep DiveServerless Development Deep Dive
Serverless Development Deep DiveAmazon Web Services
 
Multi-Account Strategy At Scale - Nick Bausch, Chicago
Multi-Account Strategy At Scale - Nick Bausch, ChicagoMulti-Account Strategy At Scale - Nick Bausch, Chicago
Multi-Account Strategy At Scale - Nick Bausch, ChicagoAWS Chicago
 
Containerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaContainerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaRyan Cuprak
 
Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...
Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...
Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...Amazon Web Services
 
AWS Lambda and Serverless framework: lessons learned while building a serverl...
AWS Lambda and Serverless framework: lessons learned while building a serverl...AWS Lambda and Serverless framework: lessons learned while building a serverl...
AWS Lambda and Serverless framework: lessons learned while building a serverl...Luciano Mammino
 
Experiences in Architecting & Implementing Platforms using Serverless.pdf
Experiences in Architecting & Implementing Platforms using Serverless.pdfExperiences in Architecting & Implementing Platforms using Serverless.pdf
Experiences in Architecting & Implementing Platforms using Serverless.pdfSrushith Repakula
 
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)cgmonroe
 
Large scale data capture and experimentation platform at Grab
Large scale data capture and experimentation platform at GrabLarge scale data capture and experimentation platform at Grab
Large scale data capture and experimentation platform at GrabRoman
 
Building CICD Pipelines for Serverless Applications
Building CICD Pipelines for Serverless ApplicationsBuilding CICD Pipelines for Serverless Applications
Building CICD Pipelines for Serverless ApplicationsAmazon Web Services
 
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)Amazon Web Services
 
Building an Observability Platform in 389 Difficult Steps
Building an Observability Platform in 389 Difficult StepsBuilding an Observability Platform in 389 Difficult Steps
Building an Observability Platform in 389 Difficult StepsDigitalOcean
 
Gab 2018 seguridad y escalado en azure service fabric
Gab 2018   seguridad y escalado en azure service fabricGab 2018   seguridad y escalado en azure service fabric
Gab 2018 seguridad y escalado en azure service fabricAlberto Diaz Martin
 
Gab 2018 seguridad y escalado en azure service fabric
Gab 2018   seguridad y escalado en azure service fabricGab 2018   seguridad y escalado en azure service fabric
Gab 2018 seguridad y escalado en azure service fabricAlberto Diaz Martin
 
Feedback on building Production-Ready Microsoft Teams Apps
Feedback on building Production-Ready Microsoft Teams AppsFeedback on building Production-Ready Microsoft Teams Apps
Feedback on building Production-Ready Microsoft Teams AppsGuillaume Meyer
 
Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...
Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...
Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...Amazon Web Services
 
DevOps, Microservices and Serverless Architecture
DevOps, Microservices and Serverless ArchitectureDevOps, Microservices and Serverless Architecture
DevOps, Microservices and Serverless ArchitectureMikhail Prudnikov
 
Mt logging with_bam
Mt logging with_bamMt logging with_bam
Mt logging with_bamAmani Soysa
 
Introduction to WSO2 Data Analytics Platform
Introduction to  WSO2 Data Analytics PlatformIntroduction to  WSO2 Data Analytics Platform
Introduction to WSO2 Data Analytics PlatformSrinath Perera
 
Evolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di PalmaEvolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di PalmaMongoDB
 

Similar to CloudWatch hidden features for debugging serverless apps (20)

Serverless Development Deep Dive
Serverless Development Deep DiveServerless Development Deep Dive
Serverless Development Deep Dive
 
Multi-Account Strategy At Scale - Nick Bausch, Chicago
Multi-Account Strategy At Scale - Nick Bausch, ChicagoMulti-Account Strategy At Scale - Nick Bausch, Chicago
Multi-Account Strategy At Scale - Nick Bausch, Chicago
 
Containerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaContainerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS Lambda
 
Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...
Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...
Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...
 
AWS Lambda and Serverless framework: lessons learned while building a serverl...
AWS Lambda and Serverless framework: lessons learned while building a serverl...AWS Lambda and Serverless framework: lessons learned while building a serverl...
AWS Lambda and Serverless framework: lessons learned while building a serverl...
 
Experiences in Architecting & Implementing Platforms using Serverless.pdf
Experiences in Architecting & Implementing Platforms using Serverless.pdfExperiences in Architecting & Implementing Platforms using Serverless.pdf
Experiences in Architecting & Implementing Platforms using Serverless.pdf
 
test-sgsgsgs.pptx
test-sgsgsgs.pptxtest-sgsgsgs.pptx
test-sgsgsgs.pptx
 
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
 
Large scale data capture and experimentation platform at Grab
Large scale data capture and experimentation platform at GrabLarge scale data capture and experimentation platform at Grab
Large scale data capture and experimentation platform at Grab
 
Building CICD Pipelines for Serverless Applications
Building CICD Pipelines for Serverless ApplicationsBuilding CICD Pipelines for Serverless Applications
Building CICD Pipelines for Serverless Applications
 
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
AWS re:Invent 2016: ↑↑↓↓←→←→ BA Lambda Start (SVR305)
 
Building an Observability Platform in 389 Difficult Steps
Building an Observability Platform in 389 Difficult StepsBuilding an Observability Platform in 389 Difficult Steps
Building an Observability Platform in 389 Difficult Steps
 
Gab 2018 seguridad y escalado en azure service fabric
Gab 2018   seguridad y escalado en azure service fabricGab 2018   seguridad y escalado en azure service fabric
Gab 2018 seguridad y escalado en azure service fabric
 
Gab 2018 seguridad y escalado en azure service fabric
Gab 2018   seguridad y escalado en azure service fabricGab 2018   seguridad y escalado en azure service fabric
Gab 2018 seguridad y escalado en azure service fabric
 
Feedback on building Production-Ready Microsoft Teams Apps
Feedback on building Production-Ready Microsoft Teams AppsFeedback on building Production-Ready Microsoft Teams Apps
Feedback on building Production-Ready Microsoft Teams Apps
 
Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...
Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...
Analyze Amazon CloudFront and Lambda@Edge Logs to Improve Customer Experience...
 
DevOps, Microservices and Serverless Architecture
DevOps, Microservices and Serverless ArchitectureDevOps, Microservices and Serverless Architecture
DevOps, Microservices and Serverless Architecture
 
Mt logging with_bam
Mt logging with_bamMt logging with_bam
Mt logging with_bam
 
Introduction to WSO2 Data Analytics Platform
Introduction to  WSO2 Data Analytics PlatformIntroduction to  WSO2 Data Analytics Platform
Introduction to WSO2 Data Analytics Platform
 
Evolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di PalmaEvolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di Palma
 

Recently uploaded

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 

Recently uploaded (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 

CloudWatch hidden features for debugging serverless apps

  • 1. CloudWatch hidden features for debugging serverless application Marko (ServerlessLife) Full-stack Software Developer | AWS Certified Professional | Serverless Specialist Blog: www.serverlesslife.com Email: marko@serverlesslife.com Twitter: @ServerlessL LinkedIn: https://www.linkedin.com/in/marko-serverlesslife/
  • 2. CloudWatch Set of AWS services for observability. Observability Umbrella term for: ● Logging ● Metrics ● Tracing
  • 3. Why is it important? Complex serverless applications look like this: Source: https://dzone.com/articles/observability-driven-development-for-serverless
  • 4. Debugging serverless / microservices? Source: https://play.google.com/store/apps/details?id=com. apsocialsoft.murdermystery&hl=en_US&gl=US
  • 5. CloudWatch vs. 3rd party + quite powerful + it is already there, no issues with sharing the data - user / developer experience 👎👎👎👎👎 3rd party tools/services: Try to use services specialized for serverless: Lumigo, Epsagon, Thundra
  • 6. Lambda and CloudWatch logs Log groups ➡ multiple log stream Node.js libraries: ● https://www.npmjs.com/package/lambda-log ● https://github.com/middyjs/middy + error-logger/input-output-logger ● https://awslabs.github.io/aws-lambda-powertools-typescript/ (BETA !!!)
  • 7. ⚠Warning: CloudWatch is expensive 💸💸💸💸💸 CloudWatch is usually more expensive than Lambda. Solutions: ● Do not log too much. ● Limit retention. ● Use sampling. ● Log request and other details only in case of an error. ● Enable detailed logging only when needed.
  • 8. Logs Insights ● Takes about 1 min to update. ● Query language is extremely powerful. ● You can use regular expressions and parse the message. ● You can store the query (also with IaC). ● There are already prepared queries.
  • 9. Logs Insights sample Errors in Lambda: fields @timestamp, @message | filter @message like /ERROR/ | sort @timestamp desc
  • 10. Logs Insights sample Poor man distributed tracer: console.log("MY DATA", JSON.stringify({ orderId: 1234, customerName: 'John Smith', traceIds: ['b4346', 'fd418'] })); fields @timestamp, @message | filter @message like /b4346/ | sort @timestamp desc
  • 11. Logs Insights sample Parse string: console.log('userId:4567,city:London'); fields @timestamp, @message | parse @message /^.*userId:(?<userId>d*),city :(?<city>.*)$/ | filter userId = 4567 | display userId, city, @message | sort @timestamp desc
  • 12. Logs Insights sample Average duration, max duration, min duration, P99 percentile duration and request count: filter @type = "REPORT" | stats avg(@duration), max(@duration), min(@duration), pct(@duration, 99), count(@duration) by bin(5m) Credit: https://dev.to/aws-heroes/10-cloudwatch-logs-insights-examples-for-serverless-applications-4293
  • 13. Logs Insights sample Number of exceptions per 5-minute intervals: filter @message like /ERROR/ | stats count(*) as exceptionCount by bin(5m) | sort exceptionCount desc
  • 14. Logs Insights sample Count a number of cold starts, average init time and maximum init duration of a Lambda function filter @type="REPORT" | fields @memorySize / 1000000 as memorySize | filter @message like /(?i)(Init Duration)/ | parse @message /^REPORT.*Init Duration: (?<initDuration>.*) ms.*/ | parse @log /^.*/aws/lambda/(?<functionName>.*)/ | stats count() as coldStarts, avg(initDuration) as avgInitDuration, max(initDuration) as maxIntDuration by functionName, memorySize
  • 15. Logs Insights sample Lambda cold start percentage over time filter @type = "REPORT" | stats sum(strcontains( @message, "Init Duration")) / count(*) * 100 as coldStartPercentage, avg(@duration) by bin(5m) Credit: https://github.com/julianwood/serverless-cloudwatch-logs-insights-examples
  • 16. API Gateway The Missing Guide to AWS API Gateway Access Logs https://www.alexdebrie.com/posts/api-gateway-access-logs/
  • 17. Metrics Data is kept for 15 months. Math expressions Metrics Insights (SQL Query) - only last 3h
  • 18. Types of Metrics ● Build in ● Custom ○ Synchronously ○ Asynchronously: ■ Log something ➡ create filter to transform to metric ■ Embedded Metric Format: Log in specific format ➡ auto-transformed to metrics
  • 19. Alarms What alerts should you have for serverless applications? https://lumigo.io/blog/what-alerts-should-you-have-for-serverless-applications/ ⚠ Alarm fatigue The high number of false alarms become senseless background noise. Composite Alarms - goes into ALARM state only if all conditions of the rule are met
  • 20. Tracing with X-Ray Stores trace data for the last 30 days. How to enable: ● Enable on API Gateway & Lambda ● Add: const AWSXRay = require('aws-xray-sdk-core') const AWS = AWSXRay.captureAWS(require('aws-sdk')) ● Additional configuration for SQS, Use segments, annotation and metadata to add additional information. Additional use for segments: ● Lambda doesn’t allow us to add custom annotations and metadata to its root segment. This can be resolved by custom subsegment. ● When calling 3rd party service.
  • 22. Insights (do not mix with Logs Insights) ● Lambda Insights ● Contributor Insights ➡ DynamoDB ● …
  • 23. Dashboard ● Automatic dashboards ● Sharing ● Custom Widgets Create a Lambda that return static HTML. JavaScript is not allowed. Can be dynamic with using special tags.
  • 24. Anomaly Detection It trains on up to two weeks of metric data.
  • 25. Thank you! Don’t be a stranger: Email: marko@serverlesslife.com Blog: www.serverlesslife.com Twitter: @ServerlessL LinkedIn: https://www.linkedin.com/in/marko-serverlesslife/