Skip to content
watch on youtubeThe notes below cover everything in the video. Find it in the playlist on our channel.Open the YouTube channel
Lesson 10 of 1010 min video

Monitoring and Cost Control on AWS

Monitor AWS with CloudWatch metrics, alarms, the agent and Logs Insights, then control costs with Budgets, Cost Explorer, tags and a savings checklist.

Video chapters

  1. 00:00Intro
  2. 00:40What should you actually monitor?
  3. 01:23CloudWatch in five words
  4. 02:22Step 1: An alarm that emails you
  5. 03:22Step 2: Memory, disk and logs: the agent
  6. 04:36Step 3: Find problems in logs, fast
  7. 05:33The alarms worth having
  8. 06:29Seeing where the money goes
  9. 07:23The cost checklist
  10. 08:29Your capstone: put it all together
  11. 09:20You finished the course. What next?

Building is half the job. The other half is knowing your systems are healthy, and that they're not quietly burning money. In this final episode you set up CloudWatch monitoring and alerts, read logs efficiently, and learn the cost tools and habits that keep AWS affordable.

What you need

  • An EC2 instance (Episode 4)
  • Your admin user, and an email address for alerts

What should you actually monitor?

What should you actually watch? There are endless metrics, but Google's site reliability engineers popularized four golden signals, and they're a great place to start.

Latency: how long requests take. Slow is the new down.

Traffic: how much demand there is, like requests per second, or active users.

Errors: how many requests fail, like five hundred errors, exceptions, or timeouts.

And saturation: how full your resources are. C P U, memory, disk space, and database connections.

The goal of all monitoring is simple: you should know something is wrong before your users tell you. Every alert you create should serve that goal, and nothing else.

Quick reference

  • Latency: How long requests take
  • Traffic: How many requests, users, messages
  • Errors: Failed requests: 5xx, exceptions, timeouts
  • Saturation: How full: CPU, memory, disk, connections
  • The goal: Know before your users tell you

CloudWatch in five words

CloudWatch is AWS's monitoring service. Five words again. Metrics are numbers over time, like C P U utilization, or network traffic.

Alarms watch a metric, and do something when it crosses a threshold, like sending you an email.

Here's an important detail many beginners miss. EC2 sends some metrics automatically, like C P U, network, and status checks. But memory usage and disk space are not among them. AWS can see the virtual hardware, not what's happening inside your operating system. For those, you install the CloudWatch agent, which we'll do shortly.

Logs collects log files from servers and AWS services, organized into log groups.

Logs Insights lets you search them with a simple query language.

And dashboards put the graphs that matter on one page. Build one per application, with the golden signals at the top.

Quick reference

  • Metrics: Numbers over time: CPUUtilization, NetworkIn…
  • Alarms: Watch a metric, act when it crosses a line
  • Logs: Log groups and streams from servers and services
  • Logs Insights: Query language to search logs fast
  • Dashboards: Graphs of what matters, on one page

EC2 metrics · built in

CPUUtilization        yes
NetworkIn / Out       yes
StatusCheckFailed     yes
EBS read/write        yes

Memory used           agent
Disk space used       agent
App logs              agent

Step 1 · An alarm that emails you

Step one: an alarm that emails you. Alarms send notifications through S N S, simple notification service. Create a topic, called ops alerts.

Add an email subscription. AWS sends a confirmation email, and nothing arrives until you click the link in it. This is the step people forget.

Now open CloudWatch, go to alarms, and create an alarm.

Select the EC2 C P U utilization metric for your web server.

Set the condition: greater than eighty percent, for two consecutive five minute periods. Requiring two periods stops you being woken up by a single short spike.

For the action, notify the ops alerts topic. Add a second notification for when the alarm returns to OK, so you also know when the problem is over. An alarm has three states: OK, alarm, and insufficient data, which usually means the metric isn't arriving.

Quick reference

  1. SNS → Create topic: ops-alerts
  2. Subscription: Email → confirm the link in your inbox
  3. CloudWatch → Alarms → Create alarm
  4. Metric: EC2 → CPUUtilization for web-1
  5. Condition: > 80% for 2 of 2 periods (5 min)
  6. Action: notify ops-alerts · also on OK

ALARM STATES

OK                 all good
ALARM              threshold crossed
INSUFFICIENT_DATA  no data yet

Email on ALARM  →  and again on OK

Step 2 · Memory, disk and logs: the agent

Step two: the CloudWatch agent, for memory, disk, and log files. First, the server needs permission to send data. Attach an I A M role with the AWS managed policy called CloudWatch agent server policy. Roles again, no keys.

Then install the agent. On Amazon Linux, it's a single package. On Ubuntu, you download the package from AWS's documentation page.

The dnf install command does it on Amazon Linux.

The agent includes a configuration wizard, which asks you questions and writes the config file for you.

Choose to collect memory used percent, disk used percent, and your application's log files, like the nginx logs.

Then load that configuration and start the agent, with the agent control command shown here. Within a few minutes, the new metrics appear in CloudWatch, under a namespace called CW agent, and your logs appear in log groups.

Now create an alarm on disk used percent above eighty five percent. Remember from episode two: full disks cause more outages than you'd expect. This alarm catches it days before it happens.

Quick reference

sudo dnf install -y amazon-cloudwatch-agent
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
    -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
Tip: Then alarm on disk_used_percent > 85%. Full disks cause real outages.

Step 3 · Find problems in logs, fast

Step three: finding problems in logs. When an alarm fires, logs tell you why. Open CloudWatch Logs Insights.

Select one or more log groups, and a time range, like the last hour.

This query shows the twenty most recent lines containing the word error. Fields picks the columns, filter keeps matching lines, sort puts the newest first, and limit keeps it short. It searches millions of lines in seconds.

You can also count things. This one counts errors in five minute buckets.

Turn it into a graph, and you can see exactly when the errors started, which you can line up with your deployments from the CI/CD pipeline. Very often, the answer is: right after the last deploy.

And set a retention period on each log group, like thirty days. By default, CloudWatch keeps logs forever, and log storage is a common hidden cost.

Quick reference

  1. CloudWatch → Logs Insights
  2. Select log group(s) + time range
  3. Count errors per 5 minutes:
  4. Set log retention (e.g. 30 days) to control cost

query · latest errors

fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 20

query · error rate

filter @message like /ERROR/
| stats count(*) by bin(5m)

The alarms worth having

Which alarms are worth having? Too many alarms, and you start ignoring them. Start with these five.

Status check failed. It means the instance or the hardware underneath is unhealthy. An alarm on the system status check can even trigger EC2's recover action automatically.

Disk above eighty five percent, from the agent.

Five hundred errors. If you use a load balancer, it reports them as a metric. Otherwise, a metric filter can count error lines in your logs, and you alarm on that count.

For RDS: free storage space running low, high C P U, and the number of database connections.

And the budget alert from episode three, because a sudden cost spike is often the first sign that something is wrong, like a runaway process, or a compromised key. Every alarm should be actionable: when it fires, you know what to check first.

Quick reference

  • Status check failed: Instance unhealthy. Can trigger auto-recover
  • Disk > 85%: Agent metric. Days of warning
  • 5xx errors: From a load balancer, or a log metric filter
  • Database: RDS: free storage low, CPU high, connections
  • Budget: AWS Budgets alert (Episode 3)

Seeing where the money goes

Now the money side. Here are the tools that show you where it goes.

Cost Explorer graphs your spending by service, region, day, or tag. When the bill rises, this is where you find out why.

Remember the project tag we've used since episode three? Activate it as a cost allocation tag, in the billing console. After that, Cost Explorer can show you exactly what each project costs. It only works for costs from after you activate it, so do it early.

Budgets, which you already have, alert you on actual and forecasted spend.

Cost anomaly detection learns your normal spending, and alerts you when something unusual happens, like a service suddenly costing ten times more than usual.

And Compute Optimizer looks at your real usage, and recommends smaller or cheaper instance types when you've over-provisioned.

Quick reference

  • Cost Explorer: Spend by service, region, day, or tag
  • Cost allocation tags: Activate your project tag in Billing
  • Budgets: Alerts on actual and forecast spend
  • Anomaly Detection: Flags unusual spending patterns
  • Compute Optimizer: Right-sizing recommendations

The cost checklist

And here's the checklist that saves most of the money in real companies.

Delete what's unused. Idle instances, old snapshots, unattached E B S volumes, and unused Elastic IPs. These are the classic forgotten costs.

Right-size. Most servers are bigger than they need to be. Check the metrics, and step down a size when the C P U and memory are mostly idle.

Schedule development environments. A test server only needed during working hours can be stopped at night and on weekends, which removes a large share of its running hours. A scheduled rule, or an n-eight-n workflow, can do this automatically.

Use storage lifecycles: the S3 classes from episode five, and log retention from today.

And for usage that runs all the time, like a production database server, Savings Plans or reserved capacity can cut the price significantly, in exchange for a one or three year commitment. Only commit once your usage is stable.

Quick reference

  • Delete the unused: Idle instances, old snapshots, unattached volumes, IPs
  • Right-size: Most servers are bigger than they need to be
  • Schedule dev: Stop dev/test at night and weekends
  • Storage lifecycle: S3 classes + log retention
  • Commit for steady load: Savings Plans for always-on usage

Your capstone: put it all together

That's the end of the lessons. Now, your capstone project, which uses every episode of this course.

Write Terraform that creates the infrastructure: a server, a private RDS database, and an S3 bucket.

Package a small web app with Docker, and push it to E C R.

Build a GitHub Actions pipeline that tests the app, and deploys it, using OIDC.

Run it on EC2, or on E C S if you want a challenge, connected to the private database.

Add CloudWatch alarms and log queries.

And a budget, with alerts.

Then put it on GitHub, with a clear README, an architecture diagram, and a short section on what you'd improve next. A project like this, that you can explain end to end in an interview, is worth more than any number of tutorials watched.

Quick reference

Terraform → Docker + ECR → CI/CD → EC2 / ECS + RDS → CloudWatch → Budgets

You finished the course. What next?

Congratulations. You've finished the Road to Cloud Engineer course. Here's what I'd do next.

Build the capstone. And when it works, run terraform destroy, and watch everything disappear cleanly. That moment is when infrastructure as code really clicks.

If you want certifications, you're now well prepared to start on the AWS Certified Cloud Practitioner, and then the Solutions Architect Associate.

Go deeper: designing your own V P C networks, running containers on E C S with Fargate, serverless with Lambda, and eventually Kubernetes.

Share your work. A GitHub repository, a short LinkedIn post about what you built and what you learned, and you've started a portfolio that speaks for you.

The notes for all ten episodes are on the HighQ Prompts website, linked in the description. Thank you for learning with me. Tell me in the comments what you built, and what you'd like the next course to cover.

Quick reference

  • Build the capstone: Then destroy it with terraform destroy
  • Certify: Cloud Practitioner → Solutions Architect Associate
  • Go deeper: VPC design, ECS Fargate, serverless, Kubernetes
  • Share your work: GitHub, LinkedIn post, a short write-up
  • Keep the notes: All 10 episodes on the HighQ Prompts website

Practice

  1. Create a CPU alarm, then trigger it with a stress test (e.g. the stress-ng tool).
  2. Send nginx logs to CloudWatch Logs and query 404s with Logs Insights.
  3. Activate your project tag as a cost allocation tag and group Cost Explorer by it.

Next episode

Capstone: deploy a complete app with Terraform, Docker/ECR, RDS, CI/CD and monitoring, and share it in the comments.

Key takeaways

  • Watch latency, traffic, errors and saturation, so you know before your users tell you
  • CloudWatch alarms email you through SNS; the agent adds memory, disk and log data
  • Cost Explorer, cost allocation tags, Budgets and Anomaly Detection show where money goes
  • Delete what's unused, right-size, stop dev at night and use Savings Plans for steady load