0Pricing
AWS Security Academy · Lesson

Collecting Logs into CloudWatch

Understand how log groups and streams gather data from services.

Collecting Logs into CloudWatch is a free AWS Security Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What CloudWatch Logs Is

Amazon CloudWatch Logs is the managed service that collects, stores, and searches log data from your AWS resources and applications. Instead of logs sitting on individual servers where they can be lost when an instance terminates, they stream to a central, durable place. For a security engineer, this centralization is the whole point: you cannot detect or investigate what you cannot see.

Log Groups

A log group is a container that holds related log data and defines shared settings. Typically one log group represents one application or service, such as /aws/lambda/my-function. Two settings matter most for security: the retention period, which controls how long logs are kept before automatic deletion, and the optional KMS key used to encrypt the data at rest.

Log Streams

Inside a log group, a log stream is a sequence of events from a single source, like one EC2 instance or one Lambda invocation environment. Events arrive with a timestamp and a message. Splitting by stream keeps sources separate so you can trace activity back to a specific origin while still grouping everything logically under one log group.

The Unified CloudWatch Agent

EC2 instances and on-premises servers do not send logs automatically. The unified CloudWatch agent is installed on the host to ship operating-system, application, and custom log files into CloudWatch Logs. It also collects extra metrics such as memory and disk usage that the hypervisor cannot see. The agent needs an IAM role granting it permission to write logs.

Native Service Integrations

Many AWS services log directly to CloudWatch with no agent at all. Lambda writes function output, VPC Flow Logs can target a log group, and Route 53 can log DNS queries. CloudTrail can also deliver events to CloudWatch Logs in addition to S3. Knowing which sources are agentless versus agent-based is a common exam distinction.

Retention and Cost

By default log groups keep data forever, which quietly grows your bill. You set retention per log group, from one day up to ten years. Security and compliance often demand long retention for audit trails, while noisy debug logs can expire quickly. Balancing the two keeps both auditors and your finance team satisfied.

Encrypting Log Data

CloudWatch Logs encrypts data at rest by default, but you can associate a customer managed KMS key with a log group for tighter control. This lets you govern exactly who can read the logs through the key policy and produces an auditable record of key usage. Sensitive logs containing credentials or PII benefit most from this.

aws logs associate-kms-key \
  --log-group-name /aws/lambda/payments \
  --kms-key-id arn:aws:kms:us-east-1:111122223333:key/abcd-1234

Subscription Filters

A subscription filter streams matching log events in near real time to another destination such as Lambda, Kinesis Data Streams, or Amazon OpenSearch. Security teams use this to forward logs to a SIEM or to a central logging account the moment events arrive, rather than batch-exporting later. It turns CloudWatch Logs into a live pipeline.

Exporting Logs to S3

For long-term, low-cost archival you can export log data to Amazon S3. S3 offers cheaper storage, lifecycle rules to Glacier, and Object Lock for immutability. A common pattern is short retention in CloudWatch for fast search plus an export to a locked-down S3 bucket for the years-long compliance record.

CloudWatch Logs Insights

CloudWatch Logs Insights is a purpose-built query language for searching log groups interactively. You can filter, aggregate, and sort across huge volumes without exporting anything. During an investigation it lets you quickly answer questions like which IP triggered the most errors, making it a fast first step before moving to Athena for deeper analysis.

Securing the Pipeline

The logging pipeline is itself a target. Grant the CloudWatch agent role only logs:CreateLogStream and logs:PutLogEvents, never broad permissions. Protect log groups so attackers cannot delete them to hide activity, and forward critical logs to a separate account quickly. A log you control end to end is evidence you can trust.

Quick Check

Test your grasp of CloudWatch Logs collection.

Recap

CloudWatch Logs centralizes log data into log groups made of log streams. EC2 and on-prem hosts need the unified agent, while many services integrate natively. Set retention to control cost, attach a KMS key for sensitive data, and use subscription filters or S3 export to feed a SIEM or archive. Locking down the pipeline keeps your evidence trustworthy.

Frequently asked questions

Is the “Collecting Logs into CloudWatch” lesson free?

Yes — the full text of “Collecting Logs into CloudWatch” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.

What will I learn in “Collecting Logs into CloudWatch”?

Understand how log groups and streams gather data from services. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Security Academy?

No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Collecting Logs into CloudWatch” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Security Academy lesson?

Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Collecting Logs into CloudWatch
  2. Metric Filters for Security Events
  3. Creating Alarms and Notifications
  4. Detecting Root Account Usage
← Back to AWS Security Academy