AWS DevOps: Collection, Aggregation, and Storage of Logs and Metrics
Configure the collection, aggregation, and storage of logs and metrics.
AWS DevOps: Collection, Aggregation, and Storage of Logs and Metrics
This guide focuses on Domain 4.1 of the AWS Certified DevOps Engineer Professional exam: establishing a robust observability pipeline for applications and infrastructure.
Learning Objectives
After studying this guide, you should be able to:
- Implement custom metric collection using the CloudWatch Unified Agent.
- Configure real-time log ingestion and processing using CloudWatch Subscriptions.
- Design secure storage and lifecycle policies for logs and metrics using Amazon S3 and KMS.
- Aggregate monitoring data across multiple AWS regions and accounts for a centralized view.
- Apply encryption at-rest and in-transit for sensitive log data.
Key Terms & Glossary
- Namespace: A container for CloudWatch metrics. Metrics in different namespaces are isolated from each other.
- Dimension: A name/value pair that is part of the identity of a metric (e.g.,
InstanceId). - Metric Filter: A feature that searches for and matches terms or patterns in log events and turns them into numerical CloudWatch metrics.
- Metric Stream: A continuous, high-volume stream of CloudWatch metrics to a destination like S3 or Kinesis Data Firehose.
- CloudWatch Logs Insights: An interactive query tool for searching and analyzing log data using a specialized syntax.
- VPC Flow Logs: A feature that captures information about the IP traffic to and from network interfaces in your VPC.
The "Big Idea"
In a DevOps culture, Observability is the prerequisite for automation. You cannot automate recovery or scaling if you cannot measure state. This module covers the "plumbing" of observability: how to move data from where it is generated (EC2, Lambda, Containers) to where it can be analyzed (CloudWatch Dashboards, OpenSearch) or stored long-term (S3), while maintaining security and cost-efficiency.
Formula / Concept Box
| Concept | Rule / Specification |
|---|---|
| Metric Resolution | Standard Resolution (1-minute) vs. High Resolution (down to 1-second). |
| Log Retention | Can be set from 1 day to "Never Expire". Default is "Never Expire". |
| CloudWatch Agent | Required for OS-level metrics (RAM utilization, Disk space, Swap). |
| Aggregation | Use CloudWatch Cross-Account Observability or AWS Config Aggregators for multi-account setups. |
Hierarchical Outline
- Data Collection
- Standard Metrics: Default metrics provided by AWS services (CPU, Disk I/O, Network).
- Custom Metrics: Pushed via CLI/SDK or the CloudWatch Unified Agent.
- Log Ingestion: Log Groups and Log Streams; using the agent to tail local log files.
- Aggregation & Processing
- Metric Filters: Extracting data from logs (e.g., counting "404" errors).
- Subscription Filters: Real-time streaming to Lambda, Kinesis, or OpenSearch.
- Metric Streams: Low-latency export to third-party providers (Datadog, New Relic) or S3.
- Storage & Lifecycle
- Retention Policies: Automatically deleting or archiving logs to save costs.
- S3 Tiering: Moving logs from S3 Standard to Glacier for long-term compliance.
- Security & Encryption
- KMS Integration: Encrypting log groups at rest with Customer Managed Keys (CMK).
- IAM Permissions: Roles for the agent to
PutMetricDataandPutLogEvents.
Visual Anchors
Log Processing Flow
Metric Data Model
Definition-Example Pairs
- CloudWatch Agent: A software package installed on hosts to collect internal system metrics.
- Example: Collecting
mem_used_percentfrom an EC2 instance, which is not available by default via the hypervisor.
- Example: Collecting
- Subscription Filter: A mechanism to route log data to other services in real-time.
- Example: Sending error logs to a Lambda function that immediately posts a message to a Slack channel.
- KMS Log Encryption: Using AWS Key Management Service to encrypt log data at the Log Group level.
- Example: A financial application must encrypt PII in logs using a rotation-enabled CMK to meet PCI-DSS compliance.
Worked Examples
Example 1: Creating a Metric Filter
Scenario: You want to monitor the number of failed login attempts in an application log.
- Pattern:
[timestamp, ip, user, message = "*Failed login*"] - Action: Create a Metric Filter on the Log Group.
- Metric Value: Increment by
1for every match. - Result: A new custom metric appears in CloudWatch, allowing you to set an Alarm if failed logins exceed 10 in 5 minutes.
Example 2: Cross-Account Metric Aggregation
Scenario: A DevOps engineer needs to see metrics from 50 different accounts in a single dashboard.
- Source Accounts: Configure "CloudWatch Permissions" to share data.
- Monitoring Account: Link the source accounts.
- Dashboard: Select metrics from multiple accounts using the account dropdown in the metric picker.
Checkpoint Questions
- What is the main difference between standard resolution and high resolution metrics?
- Which service should you use if you need to perform complex SQL-like queries on your logs stored in CloudWatch?
- How do you ensure that logs are automatically moved to cheaper storage after 90 days?
- What IAM permission is strictly required for an EC2 instance to send logs to CloudWatch?
▶Click to see answers
- Standard resolution is 1-minute; High resolution is 1-second (ideal for sub-minute spikes).
- CloudWatch Logs Insights.
- Set a "Retention Policy" on the Log Group or use S3 Lifecycle policies if logs are exported to S3.
logs:CreateLogStreamandlogs:PutLogEvents.
Muddy Points & Cross-Refs
- CloudWatch vs. AWS Config: CloudWatch monitors performance and logs; AWS Config monitors configuration changes and compliance. Use Config Aggregators for centralized compliance state, not for application logs.
- Metric Streams vs. Subscriptions: Use Metric Streams for metrics (numbers) and Subscription Filters for logs (text).
- High Resolution Cost: Remember that high-resolution metrics incur higher costs due to the frequency of data points.
Comparison Tables
| Feature | CloudWatch Logs | Amazon S3 | Kinesis Data Firehose |
|---|---|---|---|
| Primary Use | Real-time search/alerts | Long-term archiving | Real-time delivery to destinations |
| Query Method | Logs Insights | Athena / S3 Select | Not applicable (transit only) |
| Retention | Configurable per group | Lifecycle Policies | 24h - 365d (if using Streams) |
| Cost Profile | Moderate (Ingestion based) | Low (Storage based) | Moderate (Throughput based) |