EduFlow
AWS Cloud Foundations
0%

Section 4 · Building Something Real

Observe with CloudWatch, Review with Well-Architected

13 min3 min readFill in the blanks

Lesson at a glance

Watch Lantern in production with CloudWatch metrics, logs and alarms, then review the whole design against the six Well-Architected pillars with cost optimisation in mind.

  1. 1Metrics: what is happening
  2. 2Logs: why it happened
  3. 3Alarms: tell a human
  4. 4The Well-Architected review
  5. 5Cost optimisation as a habit

No video here — just the real thing: a written lesson, runnable examples, a quiz and practice.

Lantern is live: the site on CloudFront, RSVPs on Lambda and DynamoDB, events in RDS. On the old server, “monitoring” meant a volunteer noticing that the site was down. This lesson gives Lantern eyes, with Amazon CloudWatch, and then steps back to review the whole design with the AWS Well-Architected Framework.

Metrics: what is happening

AWS services publish metrics to CloudWatch automatically. Each lives in a namespace and has dimensions, such as AWS/Lambda with FunctionName=lantern-rsvp. The handful that matter most for Lantern:

Service Metric Tells you
Lambda Errors, Throttles, Duration Failures, capacity limits hit, slowness
API Gateway 5xx, 4xx, Latency What users actually experienced
DynamoDB ThrottledRequests Requests the table refused
CloudFront 5xxErrorRate, CacheHitRate (an additional metric you turn on) Edge health and how well caching works

Logs: why it happened

Anything a Lambda function writes to stdout lands in CloudWatch Logs, in the log group /aws/lambda/lantern-rsvp. Switch the function’s log format to JSON in its logging configuration, log objects rather than sentences, and you can query them later with CloudWatch Logs Insights:

Text
fields @timestamp, level, message, eventId
| filter level = "ERROR"
| sort @timestamp desc
| limit 20
Terminal
aws logs put-retention-policy \
  --log-group-name /aws/lambda/lantern-rsvp --retention-in-days 30

Alarms: tell a human

A metric nobody looks at is trivia. An alarm watches one metric against a threshold and changes state when it is crossed, notifying an Amazon SNS topic that emails the maintainers:

Terminal
aws cloudwatch put-metric-alarm --alarm-name lantern-rsvp-errors \
  --namespace AWS/Lambda --metric-name Errors \
  --dimensions Name=FunctionName,Value=lantern-rsvp \
  --statistic Sum --period 300 --evaluation-periods 1 \
  --threshold 5 --comparison-operator GreaterThanOrEqualToThreshold \
  --treat-missing-data notBreaching \
  --alarm-actions arn:aws:sns:eu-west-1:111122223333:lantern-alerts

Five errors in five minutes pages someone; an idle night, with no data at all, does not. Lantern starts with three alarms: Lambda errors, API Gateway 5xx responses, and DynamoDB throttles. Fewer, meaningful alarms beat many noisy ones that people learn to ignore.

The Well-Architected review

The AWS Well-Architected Framework is AWS’s checklist of design questions, grouped into six pillars. The free AWS Well-Architected Tool in the console walks you through them. Here is Lantern’s first review, one finding per pillar:

Pillar Lantern finding Action
Operational excellence Deploys are a sequence of manual commands Script them; then infrastructure as code
Security One volunteer still uses an IAM user Move everyone to IAM Identity Center
Reliability RDS is Multi-AZ; RSVP table has no point-in-time recovery Turn PITR on
Performance efficiency RSVP function at 128 MB takes 900 ms Test 512 MB; often faster and similar cost
Cost optimization Migration EC2 instance idle since cut-over Snapshot and terminate it
Sustainability Function runs on x86 Switch to arm64 (Graviton)

Cost optimisation as a habit

Cost runs through every lesson in this course; here it is as a checklist to run on every account:

  1. Delete what is idle. Old instances, unattached EBS volumes, unused Elastic IPs, forgotten NAT gateways.
  2. Right-size. Use metrics, not guesses, to choose instance and function sizes.
  3. Use the right pricing model. Savings Plans for the steady baseline, Spot for interruptible batch, serverless for spiky work.
  4. Let data age out. S3 lifecycle rules and log retention periods.
  5. Keep traffic local. Gateway endpoints for S3 and DynamoDB; CloudFront in front of anything public.
  6. Tag and look. Tag every resource project=lantern, activate the tag for cost allocation, and open AWS Cost Explorer monthly. Your budget alert from lesson three is the safety net, not the plan.

That is the whole move. Lantern went from one fragile server to a set of managed pieces, each with an owner, a permission boundary, an alarm and a price you can explain. You can now set up an account safely, read and write IAM policies, pick the right core services, and ship and run a real workload, with cost and security designed in rather than bolted on.

Key takeaways

  • CloudWatch collects metrics, logs and alarms for AWS services automatically; Lambda writes to the /aws/lambda/ log group.
  • An alarm watches one metric against a threshold and notifies an Amazon SNS topic, which emails the people who can act.
  • New log groups keep data forever by default, so set a retention period on every log group to cap storage costs.
  • The Well-Architected Framework has six pillars, namely operational excellence, security, reliability, performance efficiency, cost optimization and sustainability.
  • Cost optimisation is a habit of deleting idle resources, right-sizing, using the right pricing model and tagging so you can see what each thing costs.

Further reading

Check your understanding

4 questions

Question 1 of 4

Lantern’s maintainers want to hear about RSVP failures before users complain. What should they set up?

Question 2 of 4

Six months in, CloudWatch is a surprisingly large line on Lantern’s bill. Which change most likely helps?

Question 3 of 4

In a Well-Architected review, the finding “the old migration EC2 instance is still running, three weeks after cut-over” belongs mainly to which pillar?

Question 4 of 4

Why tag every Lantern resource with project=lantern and activate that tag for cost allocation?

Practice

Fill in the blanks

Cap the logs, wire the alarm

Finish two commands from Lantern’s launch checklist. Step 1 sets a 30-day retention period on the RSVP function’s log group. Step 2 creates an alarm on the Lambda metric that counts failed invocations, and sends notifications to the lantern-alerts topic in the notification service that emails the maintainers.

# 1. Keep the RSVP function's logs for 30 days, then let them expire aws logs \ --log-group-name /aws/lambda/lantern-rsvp --retention-in-days 30 # 2. Email the maintainers when the function errors 5+ times in 5 minutes aws cloudwatch --alarm-name lantern-rsvp-errors \ --namespace AWS/Lambda --metric-name \ --dimensions Name=FunctionName,Value=lantern-rsvp \ --statistic Sum --period 300 --evaluation-periods 1 \ --threshold 5 --comparison-operator GreaterThanOrEqualToThreshold \ --alarm-actions arn:aws::eu-west-1:111122223333:lantern-alerts