Analyzing Real-Time Log Streams with Amazon Kinesis Data Streams
Analyzing real-time log streams (for example, using Amazon Kinesis Data Streams)
Analyzing Real-Time Log Streams with Amazon Kinesis Data Streams
This guide covers the architecture, configuration, and analysis techniques for real-time log streaming, a core requirement for the AWS Certified DevOps Engineer Professional (DOP-C02) exam. We focus on how to move from static log storage to active, real-time insights.
Learning Objectives
After studying this guide, you should be able to:
- Architect a real-time log processing pipeline using CloudWatch Logs and Kinesis.
- Configure subscription filters to stream log data to downstream consumers.
- Calculate shard requirements based on log volume and throughput limits.
- Differentiate between standard and enhanced fan-out consumers.
- Analyze streaming data using AWS services like Kinesis Data Analytics and CloudWatch Logs Insights.
Key Terms & Glossary
- Shard: The base throughput unit of a Kinesis data stream. It provides a fixed capacity (1MB/sec in, 2MB/sec out).
- Partition Key: A value used by producers to group data into specific shards within a stream.
- Sequence Number: A unique identifier assigned by Kinesis to each data record when it is added to a stream.
- Subscription Filter: A CloudWatch Logs feature that allows you to forward log events to Kinesis, Lambda, or OpenSearch in real-time.
- Kinesis Client Library (KCL): A Java library that helps you build consumer applications to process data from Kinesis streams efficiently.
The "Big Idea"
In modern DevOps, logs are no longer just for "post-mortem" investigations. The Big Idea is to treat logs as a continuous event stream. By piping logs into Amazon Kinesis Data Streams, you shift from reactive analysis (searching logs after a crash) to proactive monitoring (detecting 5XX errors or security threats as they happen in milliseconds).
Formula / Concept Box
| Feature | Limit / Rule | Logic |
|---|---|---|
| Shard Ingest | 1,000 records/sec or 1MB/sec | Whichever limit is reached first. |
| Shard Egress | 2MB/sec (standard) | Shared across all consumers not using enhanced fan-out. |
| Data Retention | 24 hours (default) | Can be extended up to 365 days. |
| Record Size | 1 MB (Maximum) | Includes partition key and data blob. |
| Enhanced Fan-out | 2MB/sec per consumer | Dedicated throughput for each registered consumer. |
Hierarchical Outline
- Log Ingestion Layer
- CloudWatch Logs Agent: Installed on EC2/on-prem to collect files.
- Metric Filters: Extract specific patterns to create CloudWatch Metrics.
- Subscription Filters: The "bridge" that pushes logs to Kinesis.
- The Processing Core: Kinesis Data Streams
- Sharding Strategy: Scaling based on
IncomingBytesandIncomingRecords. - Ordering: Records with the same Partition Key are sent to the same shard and processed in order.
- Sharding Strategy: Scaling based on
- Consumption & Analysis
- Kinesis Data Firehose: To deliver logs to S3, Redshift, or OpenSearch (near real-time).
- AWS Lambda: For simple transformations or real-time alerting.
- Kinesis Data Analytics: SQL-based analysis on the live stream.
Visual Anchors
Log Stream Architecture
Anatomy of a Kinesis Data Record
Definition-Example Pairs
- Partition Key: A value provided by the producer to determine shard assignment.
- Example: Using
Customer_IDas a partition key ensures all logs for a specific customer are processed in the exact order they occurred by the same shard.
- Example: Using
- Metric Filter: A rule to turn log patterns into numerical metrics.
- Example: Searching for the string "ERROR" in logs and incrementing a CloudWatch metric called
ErrorCountevery time it appears.
- Example: Searching for the string "ERROR" in logs and incrementing a CloudWatch metric called
- Kinesis Data Analytics: A service that runs SQL queries against streaming data.
- Example: Calculating a rolling 5-minute average of 404 errors from a website clickstream log to detect a broken link immediately.
Worked Examples
Scenario: Streaming Web Server Logs to Amazon OpenSearch
Goal: Provide a real-time dashboard for a DevOps team to see HTTP 500 errors.
- Configure CloudWatch Logs: Ensure logs are flowing into a Log Group (e.g.,
/aws/vendedlogs/alb). - Create Kinesis Data Stream: Provision a stream with 2 shards (providing 2MB/s ingest capacity).
- Setup Subscription Filter:
- Pattern:
[ip, user, id, time, request, status_code=500, size] - Destination: Select the Kinesis Data Stream.
- Pattern:
- Connect Firehose: Create a Kinesis Data Firehose delivery stream using the Data Stream as the source.
- Destination: Set Amazon OpenSearch Service as the destination for the Firehose stream.
- Result: Within 60 seconds of a 500 error occurring, it appears in the OpenSearch dashboard.
Checkpoint Questions
- What is the maximum size of a single Kinesis Data Record?
- If you have 3 consumers reading from the same shard without using Enhanced Fan-out, what is the total shared egress throughput available?
- Which field in a Kinesis record ensures that data is stored and processed in the correct order within a shard?
- How do you scale a Kinesis Data Stream that is experiencing
ProvisionedThroughputExceededExceptionerrors?
▶Click to see answers
- 1 MB.
- 2 MB/sec (shared among all three).
- Sequence Number (though the Partition Key determines which shard it goes to).
- Increase the number of shards (Resharding).
Muddy Points & Cross-Refs
- KDS vs. Kinesis Data Firehose: KDS is for processing (you write code/Lambda to read it); Firehose is for delivery (it pushes data to S3/Redshift/OpenSearch automatically). Firehose is near-real-time (60s+ latency), while KDS is sub-second.
- Ordering across shards: Kinesis only guarantees ordering within a shard. If your data spans multiple shards, you must use timestamps in your payload to re-order them downstream if absolute global ordering is required.
Comparison Tables
Kinesis Data Streams vs. Kinesis Data Firehose
| Feature | Kinesis Data Streams (KDS) | Kinesis Data Firehose |
|---|---|---|
| Primary Purpose | Low-latency ingestion & custom processing. | Loading data into AWS data stores. |
| Latency | < 200 ms (Sub-second). | 60 seconds to 15 minutes. |
| Scaling | Manual/Auto-scaling (Shards). | Fully Managed (Automatic). |
| Data Retention | 1 to 365 days. | None (Ephemeral). |
| Cost | Hourly per shard + per 1M PUT units. | Per GB of data ingested. |
[!TIP] For the exam, if the requirement asks for "Real-time" analysis with SQL, choose Kinesis Data Analytics. If it asks for "Near real-time" delivery to S3, choose Kinesis Data Firehose.