Log Aggregation with Kinesis, Firehose, S3, Athena and OpenSearch
Overview
A mature organisation does not read logs account by account. It builds a centralised logging pipeline: every account and workload streams logs to a dedicated log archive account, where they are stored cheaply, searched interactively and analysed for security and operations.
Picture a national library: books (logs) from every branch are sent to the central archive, catalogued, shelved for the long term in cold storage, while a reading room (OpenSearch dashboards) gives quick access to the most recent and most important material. Kinesis and Firehose are the delivery trucks that move the books reliably.
The exam compares Kinesis Data Streams (custom consumers, ordering, replay), Data Firehose (managed delivery with buffering and transforms), OpenSearch (search and dashboards), S3 + Athena (cheap analytics) and CloudTrail Lake (SQL over audit events), and asks which fits a given latency, cost and retention requirement.
Key Concepts
- Kinesis Data Streams is a durable, ordered, replayable stream (24 h default retention, up to 365 days) with provisioned or on-demand capacity and multiple consumers.
- Amazon Data Firehose is a fully managed delivery service to S3, Redshift, OpenSearch, Splunk, HTTP endpoints, with buffering, Lambda transformation, format conversion to Parquet/ORC and dynamic partitioning.
- OpenSearch Service (or Serverless) provides full-text search, dashboards and alerting; it needs capacity planning, shard sizing and UltraWarm / cold tiers for retention.
- S3 + Athena is the cheapest long-term store: partition by date/account/Region, use Parquet and the Glue Data Catalog; Lake Formation can govern access.
- CloudTrail Lake is a managed event data store with SQL queries and organisation-wide ingestion; organisation trails deliver to a central S3 bucket.
- A log archive account (Control Tower's design) holds immutable logs; bucket policies enforce TLS, org-only writes and S3 Object Lock.
- Subscription filters, Firehose direct puts, agents (Fluent Bit, Kinesis agent) and VPC Flow Logs/ALB/S3 access logs to S3 feed the pipeline.
- Choose by need: seconds-latency search = OpenSearch; cheap long retention + ad hoc SQL = S3/Athena; custom real-time processing = Kinesis consumers or Lambda.
Detailed Notes
Service roles in the pipeline
| Service | Role | Latency | Cost profile |
|---|---|---|---|
| Kinesis Data Streams | Ingest, buffer and fan out | Sub-second to ~200 ms | Per shard-hour or on-demand throughput |
| Data Firehose | Load into stores with transformation | 60 s to 15 min buffering (zero-buffering available for some destinations) | Per GB ingested |
| OpenSearch | Search, dashboards, alerting | Seconds | Instance/storage hours (or OCUs for Serverless) |
| S3 + Athena | Archive + SQL | Minutes to query | Cheap storage, pay per TB scanned |
| CloudTrail Lake | Audit event queries | Minutes | Per GB ingested and scanned |
Reference architecture
- Workloads write logs to CloudWatch Logs (or S3 for service logs).
- Subscription filters send events to a cross-account destination backed by Kinesis Data Streams in the log archive account.
- Firehose reads the stream (or receives direct puts), transforms with Lambda, converts to Parquet, partitions by
account/region/dateand writes to S3. - A second Firehose (or Lambda) indexes recent data into OpenSearch with failed documents going to an S3 backup bucket.
- Athena + Glue query the archive; Dashboards show recent operations and security data.
Firehose delivery stream (CloudFormation)
LogsDelivery:
Type: AWS::KinesisFirehose::DeliveryStream
Properties:
DeliveryStreamType: KinesisStreamAsSource
KinesisStreamSourceConfiguration:
KinesisStreamARN: !GetAtt CentralStream.Arn
RoleARN: !GetAtt FirehoseRole.Arn
ExtendedS3DestinationConfiguration:
BucketARN: !GetAtt ArchiveBucket.Arn
RoleARN: !GetAtt FirehoseRole.Arn
Prefix: "logs/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
ErrorOutputPrefix: "errors/!{firehose:error-output-type}/"
BufferingHints: { IntervalInSeconds: 300, SizeInMBs: 128 }
CompressionFormat: UNCOMPRESSED
DataFormatConversionConfiguration:
Enabled: true
InputFormatConfiguration: { Deserializer: { OpenXJsonSerDe: {} } }
OutputFormatConfiguration: { Serializer: { ParquetSerDe: {} } }
SchemaConfiguration:
DatabaseName: logs
TableName: app_logs
RoleARN: !GetAtt FirehoseRole.Arn
Note how Firehose prefixes use !{timestamp:...} rather than ${...}. When the destination is OpenSearch, enable S3 backup for failed documents and size retries.
Kinesis Data Streams vs Firehose
| Question | Streams | Firehose |
|---|---|---|
| Custom consumers or multiple readers | Yes (up to 20 enhanced fan-out) | No |
| Replay and ordering by partition key | Yes | No |
| Managed delivery to S3/OpenSearch | No (needs consumer) | Yes |
| Need to manage shards | Provisioned: yes; on-demand: no | No |
Streams throughput per shard: 1 MB/s or 1,000 records/s in, 2 MB/s out. Use on-demand mode for unpredictable load. Hot partition keys cause ProvisionedThroughputExceeded.
OpenSearch design points
- Use time-based indices (daily/weekly) with Index State Management (ISM) to roll over, move to UltraWarm, then delete.
- Keep shard size 10-50 GB; too many small shards waste memory.
- Place in a VPC, with fine-grained access control (IAM/SAML), KMS encryption and node-to-node TLS.
- Three AZs with dedicated master nodes for resilience; snapshots go to S3.
- OpenSearch Serverless removes capacity management for time series collections.
Athena cost control
SELECT account_id, count(*) AS denied
FROM logs.vpc_flow
WHERE day BETWEEN '2025-03-01' AND '2025-03-07' AND action = 'REJECT'
GROUP BY account_id ORDER BY denied DESC LIMIT 20;
Partition projection, Parquet and compression cut scanned data by 90% or more. Apply S3 lifecycle to Glacier for long retention and Object Lock for tamper resistance.
Security logging specifics
- Organisation trail to the log archive bucket with log file validation and SSE-KMS.
- CloudTrail Lake event data store can span accounts with a delegated administrator.
- Enable S3 data events and Config to the same archive, and use Security Lake to normalise to OCSF for SIEM tools.
Pipeline sizing and failure handling
- Kinesis Data Streams provisioned shards give 1 MB/s or 1,000 records/s in per shard and 2 MB/s out; on-demand mode scales automatically. Use enhanced fan-out for several consumers.
- Firehose buffers by size or time (60-900 s), can transform with Lambda, convert to Parquet/ORC and writes failed records to an error prefix in S3.
- OpenSearch needs shard planning, Index State Management to roll over and delete indices, UltraWarm/cold tiers for older data, and fine-grained access control.
- Monitor the pipeline itself:
IteratorAgeMilliseconds,WriteProvisionedThroughputExceeded, FirehoseDeliveryToS3.Successand subscription filter delivery errors. - Compress and partition (
year/month/day/account) so Athena scans less data.
Real World Example
Scenario: a retailer must retain logs 7 years and search the last 14 days quickly. Application logs flow through CloudWatch Logs subscription filters into a Kinesis stream in a log archive account. One Firehose converts to Parquet in S3 (lifecycle to Glacier after 90 days, Object Lock), another loads OpenSearch where ISM deletes indices after 14 days.
Security analysts run Athena queries over VPC Flow Logs and CloudTrail Lake queries for investigations. Cost drops 60% versus keeping everything in OpenSearch.
Architecture Diagram
Workload accounts stream into a log archive account for search and long-term analytics.
- 1Workload logs land in CloudWatch Logs in each account.
- 2Subscription filters send events to a cross-account Kinesis destination.
- 3Firehose buffers, transforms and converts records to Parquet.
- 4Data is written to partitioned S3 and indexed in OpenSearch.
- 5Analysts use dashboards for recent data and Athena for history.
Best Practices
- ✓Use a dedicated log archive account with restricted write-only access and Object Lock.
- ✓Store logs as partitioned Parquet and query with Athena.
- ✓Keep only recent data in OpenSearch and use ISM and UltraWarm for ageing.
- ✓Enable backup of failed deliveries to S3 and alarm on Firehose delivery errors.
- ✓Use on-demand Kinesis or monitor shard metrics, and choose partition keys that spread load.
Common Interview Questions
Exam Tips
DOP-C02 focus
- "Near-real-time delivery to S3/OpenSearch with minimal management" = Firehose.
- "Multiple independent consumers / replay" = Kinesis Data Streams.
- "Ad hoc SQL on logs in S3" = Athena; "full-text search and dashboards" = OpenSearch.
- Hot shard errors = poor partition key distribution.
Finished this lesson?
0 of 44 lessons done · 0% of the course

