Monitoring and Auditing: CloudWatch, CloudTrail and Config
How do you know your application is healthy, who changed what, and whether your settings are still as they should be? Metrics, logs and alarms in CloudWatch, EventBridge, CloudTrail and Config, with a hands-on alarm that emails you.
- Key idea
- Definition
- When to use
- Caution
In this article
Over the previous parts we built an application with many pieces. Building it is the easy half. The hard half comes at three in the morning: is it down? Since when? And who changed that setting yesterday?
This last section is about running what you've built, and it starts with three questions, each with its own service:
| The question | The service |
|---|---|
| Is it healthy right now? | CloudWatch |
| Who did this, and when? | CloudTrail |
| Are the settings as they should be, and how have they changed? | Config |
And a fourth service reacts to all of them: EventBridge.
CloudWatch metrics
A metric is a number measured over time, such as CPU usage or the count of errors. Most AWS services send their metrics by themselves, grouped in namespaces and distinguished by dimensions, such as the server ID.
| Point | Details |
|---|---|
| EC2 default | Every 5 minutes, or every minute if you turn on detailed monitoring |
| Custom metrics | You send what you like, such as the number of failed orders, down to one-second resolution |
| History | One-minute data stays for 15 days, 5-minute data for 63 days, and hourly data for 455 days |
| Metric Streams | Sends metrics continuously through Firehose to S3 or another monitoring tool |
Dashboards put the charts you care about on one page, and they can gather metrics across Regions and accounts.
CloudWatch Logs
Everything your application prints can land here, organized into log groups that usually represent one application, and within them log streams. Lambda, ECS, API Gateway, VPC Flow Logs and others send logs directly, and on EC2 or on-premises servers you use the same agent.
Logs are kept forever by default, and you pay for that. Set a retention period on each group, from one day to ten years.
Logs Insights searches through them with a simple query language. This one gets the latest errors:
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 20
To send logs elsewhere you have two routes:
| Route | Timing | Suits |
|---|---|---|
| Export to S3 | A batch job, and not immediate | Cheap long-term archiving |
| Subscription filter | Near real time | Sending to Lambda, Kinesis or Firehose, such as for OpenSearch |
CloudWatch alarms
A chart nobody's looking at is no use. An alarm watches a metric and does something when it crosses a limit.
An alarm is in one of three states: OK, ALARM or INSUFFICIENT_DATA. Some useful additions:
- EC2 actions: stop, reboot, terminate or recover. Recovery moves the server to new hardware if the underlying host fails, keeping its IP addresses and settings.
- Composite alarms: one alarm for "high CPU and many errors", which reduces false alerts.
- Testing:
set-alarm-stateputs an alarm in any state, so you can check the alert path without breaking anything. We'll try it in the hands-on.
Ready-made insights
| Tool | What it shows |
|---|---|
| Container Insights | Metrics and logs from ECS and EKS |
| Lambda Insights | Function performance, including memory and cold starts |
| Contributor Insights | Top contributors, such as the IP addresses sending the most requests |
| Application Insights | Sets up monitoring for a whole application and points out likely problems |
EventBridge: reacting to events
Almost everything that happens in AWS is an event: a server changed state, a bucket was created, or an alarm went off. EventBridge receives these events on a bus, and rules send matching ones to a target.
| Use | Example |
|---|---|
| Reacting to a change | A server stopped, so notify the team |
| A schedule | Run a function every night; EventBridge Scheduler is the service for this now |
| Connecting your services | The orders service publishes an event, and whoever's interested takes it |
| Partner events | Events arriving from SaaS applications on a partner bus |
Features worth knowing: archive and replay to send old events again, the schema registry that describes the shape of events, and resource policies so that another account can send to your bus.
For most targets, such as Lambda, SQS and SNS, access is granted by a resource policy on the target. For others, such as starting an ECS task, EventBridge uses an IAM role.
CloudTrail: who did what
Every call to AWS, from the console, the CLI or a service, gets recorded by CloudTrail: who, what, when, and from where. It's on by default, and it's the first place to look when something changes mysteriously or disappears.
| Event type | What it covers | Default |
|---|---|---|
| Management events | Changes to resources, such as creating a server or changing a policy | On, with 90 days free in Event history |
| Data events | Operations inside resources, such as reading from S3 or invoking Lambda | Off, because of their volume |
| Insights events | Unusual activity, such as a sudden burst of delete calls | Off, at additional cost |
To keep them longer than 90 days, create a trail that writes to S3, across all Regions and even the whole organization, and analyze it with Athena. Note that CloudTrail Lake closed to new customers in 2026, so a trail is the way to go.
A powerful pattern combines it with EventBridge: anyone deleting a table, or a sign-in with the root user, immediately triggers an alert. CloudTrail records it, EventBridge matches it, and SNS tells you.
AWS Config: your settings over time
CloudTrail tells you who called what. Config tells you what a resource looks like: it records the configuration of your resources and every change to it, so you can ask what a security group looked like last Tuesday.
Config rules then judge these settings:
- Rules: managed ones ready to use, such as "no public S3 buckets", or custom ones.
- Prevention: it doesn't stop anything. It marks a resource as non-compliant, and that's it.
- Remediation: a rule can run a Systems Manager Automation document to fix the problem automatically.
- Notifications: through EventBridge or SNS.
- Scope and cost: it works per Region, and you pay per recorded item and per rule evaluation.
X-Ray: following one request
A request in a modern application can pass through an API, three functions and a database. Metrics tell you something is slow, and AWS X-Ray tells you where. It collects traces of each request as it passes through your services, including its calls to databases and other APIs, and shows you which step is slow or failing.
Other views
| Tool | What it shows |
|---|---|
| AWS Health Dashboard | Whether AWS itself has a problem affecting your services and resources, with no setup and at no cost |
| Managed Grafana | Dashboards for metrics, logs and traces from several sources, using the popular Grafana tool |
| Managed Service for Prometheus | Container metrics through the open-source Prometheus tools, with no servers to run |
Which one, when?
Let's take one load balancer:
| Example | |
|---|---|
| CloudWatch | Number of requests, 5xx errors, and a dashboard or an alarm on them |
| CloudTrail | Who changed its listener rules, and when |
| Config | Its current security group, its certificate, and how they've changed; and is it following your rules? |
Hands-on: an alarm that emails you
We'll watch a made-up metric for failed orders. From CloudShell, replace the email address with yours:
EMAIL=[email protected]
TOPIC_ARN=$(aws sns create-topic --name series-alerts \
--query TopicArn --output text)
aws sns subscribe --topic-arn $TOPIC_ARN \
--protocol email --notification-endpoint $EMAIL
Open your email and press Confirm subscription. Then create an alarm that goes off if more than five orders fail in a minute:
aws cloudwatch put-metric-alarm --alarm-name series-failed-orders \
--namespace Series/Shop --metric-name FailedOrders \
--statistic Sum --period 60 --evaluation-periods 1 \
--threshold 5 --comparison-operator GreaterThanThreshold \
--treat-missing-data notBreaching \
--alarm-actions $TOPIC_ARN
Now send the application's reading, as if 12 orders had just failed:
aws cloudwatch put-metric-data --namespace Series/Shop \
--metric-name FailedOrders --value 12
Wait two or three minutes and check the alarm's state. An email should arrive at the same time:
aws cloudwatch describe-alarms --alarm-names series-failed-orders \
--query "MetricAlarms[0].[StateValue,StateReason]" --output text
You don't have to break anything to test an alert path. Try it when the alarm has gone back to OK, and another email arrives:
aws cloudwatch set-alarm-state --alarm-name series-failed-orders \
--state-value ALARM --state-reason "Testing the alert"
Finally, play detective. Who created this alarm? CloudTrail knows, though events can take a few minutes to appear:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=PutMetricAlarm \
--max-results 1 \
--query "Events[0].[EventName,Username,EventTime]" --output text
aws cloudwatch delete-alarms --alarm-names series-failed-orders
aws sns delete-topic --topic-arn $TOPIC_ARN
Summary
- CloudWatch for metrics, logs and alarms, and memory needs the agent.
- Set a retention period on your logs, because they're kept forever by default.
- EventBridge routes events to whoever handles them, and runs things on a schedule.
- CloudTrail records who did what, and Config records the settings and judges them.
- Test your alert path before you need it.
Test yourself
Before you move on, try these questions to check you've got this part. Each one is a practical scenario, and the explanation appears once you answer.
Question 1 of 7
A team wants an alarm when memory on its EC2 servers passes 90%, but it can't find a memory metric in CloudWatch. What should it do?
Show the answer
Correct answer: B
The default metrics come from outside the server, so they don't include memory. The agent sends it from inside, and then you can put an alarm on it.
- A: This sends the same metrics more often, and memory still isn't among them.
- C: This records who called what, not how a server is performing.
- D: This records resource settings, not what's happening inside a server.
Review: CloudWatch metrics in this part, and Metrics collected by the CloudWatch agent in the AWS docs.
Question 2 of 7
An outage began right after someone changed a security group last night. The team wants to know who made the change, and from where. Where should it look first?
Show the answer
Correct answer: D
CloudTrail records who called what, when and from where. Management events like this one stay there for 90 days, with nothing to set up.
- A: These show numbers over time, not who did anything.
- B: These show the traffic that was accepted or rejected, not who changed a rule.
- C: This searches logs your applications send, not the calls made to AWS.
Review: CloudTrail: who did what in this part, and Working with CloudTrail event history in the AWS docs.
Question 3 of 7
A company wants to notice when any S3 bucket becomes public, and to fix it automatically. What fits?
Show the answer
Correct answer: A
A Config rule judges each bucket's settings and marks it as non-compliant, and a remediation can run a Systems Manager Automation document to fix it. On its own, a rule prevents nothing.
- B: Size says nothing about who can reach the bucket.
- C: This spots unusual activity, and doesn't judge or fix settings.
- D: This searches logs when you ask, and fixes nothing.
Review: AWS Config: your settings over time in this part, and Remediating Noncompliant Resources with AWS Config in the AWS docs.
Question 4 of 7
The security team wants an immediate alert whenever someone deletes a DynamoDB table or signs in with the root user. What fits?
Show the answer
Correct answer: C
CloudTrail records the call, EventBridge matches it, and SNS tells you right away.
- A: This finds them eventually, which could be days too late.
- B: A dashboard nobody's looking at alerts nobody.
- D: This judges settings, and doesn't react to a deleted table or a sign-in.
Review: CloudTrail: who did what in this part, and AWS service events delivered via AWS CloudTrail in the AWS docs.
Question 5 of 7
A team's CloudWatch Logs bill keeps growing because old logs are never removed, and another system must receive error lines within seconds. Which two changes fit? (Choose two.)
Show the answer
Correct answer: A + D
Logs are kept forever by default, so a retention period removes the old ones. A subscription filter delivers matching lines in near real time.
- B: This is a batch job that isn't immediate, and the originals stay and keep costing money.
- C: This sends EC2 metrics more often, and has nothing to do with logs.
- E: This records operations inside resources, and has nothing to do with your log bill or error lines.
Review: CloudWatch Logs in this part, and Working with log groups and log streams and Real-time processing of log data with subscriptions in the AWS docs.
Question 6 of 7
A checkout request passes through API Gateway, three Lambda functions and a DynamoDB table, and sometimes takes five seconds. Each service's metrics look normal on their own. What shows which step is slow?
Show the answer
Correct answer: C
X-Ray follows each request across your services and their calls, and shows which step is slow or failing.
- A: This records who called which API, not how long each step of a request took.
- B: This records resource settings.
- D: This shows top contributors, such as the addresses sending the most requests, not a request's path.
Review: X-Ray: following one request in this part, and What is AWS X-Ray? in the AWS docs.
Question 7 of 7
Errors suddenly rise on an application in one Region, with nothing changed on the team's side. They want to know quickly whether AWS itself has a problem affecting their resources. Where should they look?
Show the answer
Correct answer: B
It shows the events affecting AWS services and your resources, with no setup and at no cost.
- A: This shows the calls made in your account, and those didn't change here.
- C: This shows how your settings changed, and those didn't change here.
- D: This checks your account against best practices, and doesn't report outages.
Review: Other views in this part, and What is AWS Health? in the AWS docs.
You now know what's happening in one account. But companies have dozens of accounts and hundreds of employees. In part twenty-six we manage them with Organizations and Identity Center.