How does multi-line logging work in Lambda - CloudWatch
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
AWS Lambda sends function logs to CloudWatch Logs by writing runtime output streams. Multi-line logging works, but understanding how log events are grouped is important for searchability and alerting. In practice, each logging call typically creates one log event message, and that message can contain newline characters.
Lambda Logging Pipeline Basics
A Lambda invocation emits logs from two sources:
- platform logs, such as
START,END, andREPORT - application logs from
console.log,print, or language logger APIs
These messages are delivered to the CloudWatch log stream for that execution environment. Each log event has timestamp and message fields.
What Multi-Line Means in CloudWatch
If your code logs a string that contains newline characters, CloudWatch stores one event message containing embedded line breaks. In the console, this may appear as several visual lines, but logically it is still one event.
If your code calls logger methods multiple times, each call generally creates separate events.
Python example:
The first call yields one event with line breaks. The second call yields another event.
Stack Traces and Exceptions
Unhandled exceptions produce multi-line stack traces. These are usually emitted as one formatted block associated with the failure, which can appear noisy in dashboards but is valuable for debugging.
Node.js example:
This typically logs message plus stack details in CloudWatch.
Prefer Structured Single-Line JSON Logs
For reliable querying, most teams log one JSON object per line instead of arbitrary multi-line text. This avoids parsing ambiguity in CloudWatch Logs Insights.
Single-line JSON events are easier to parse, filter, and aggregate.
Query Behavior in Logs Insights
CloudWatch Logs Insights queries operate on events, not human-visible wrapped lines. If one message contains newlines, filters still see one event record. This matters when counting errors or extracting fields with parse expressions.
For JSON logs, a typical query is simpler:
Related reading
- How does the GKE metadata server work in Workload Identity
- How does waiting & atomic clock help GCP spanner solve Linearizability and Serializability in distributed transaction?
- How DynamoDB provisions throughput of reads independently of writes
- How enable access to AWS STS AssumeRole
- How does one calculate the GPU memory required to run a model in TensorFlow?
- How does one detect if one is running within a docker container within Python?
- How get Environment Variables from lambda nodejs aws-sdk
- how I can synchronized the airflow dags repository in github with an azure storage account?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.