SkillSprout
Chapter 10 · Lesson 4
Intermediate
5 min read

Observability, Structured Logging, Health Checks and Quota Alerts

Overview

Logging records what happened, monitoring watches known signals and alerts when they cross thresholds, and observability lets you ask new questions about a running system using its logs, metrics and traces together. In distributed AWS applications you need all three, tied together by a correlation ID.

Think of a hospital. Monitoring is the heart-rate monitor beeping when a pulse leaves its range. Logging is the patient's chart of events. Observability is having enough linked data (tests, history, scans) that doctors can diagnose a condition no alarm was designed for.

This lesson covers logging strategy, structured logs, custom metrics, health checks and readiness probes, and notifications for quota limits and deployment events.

Key Concepts

  • Three pillars: logs (events), metrics (numbers over time) and traces (request paths). Observability correlates them.
  • Structured logging emits JSON with consistent fields (level, requestId, tenant, orderId) so Logs Insights can filter and aggregate.
  • Propagate a correlation ID (X-Ray trace ID or request ID) through every hop and log it.
  • Embedded Metric Format (EMF) turns log lines into CloudWatch custom metrics without extra API calls.
  • Health checks: liveness says the process is alive; readiness says it can serve traffic; deep dependency checks belong in monitoring, not in load balancer checks.
  • Service Quotas exposes limits and utilisation metrics; CloudWatch alarms on quota usage warn before throttling.
  • EventBridge emits events for CodeDeploy, CodePipeline, CodeBuild, ECS and Health, enabling deployment notifications via SNS or chat.
  • CloudWatch Application Signals, RUM and Synthetics add service-level objectives, real-user monitoring and scripted canaries.

Detailed Notes

Logging, monitoring and observability compared

ConceptQuestion it answersAWS tools
LoggingWhat happened and in what order?CloudWatch Logs, Logs Insights
MonitoringIs it healthy right now?CloudWatch metrics, alarms, dashboards
TracingWhere did this request spend time?X-Ray, ADOT, Application Signals
ObservabilityWhy is it behaving this way?All of the above correlated

Structured logging with a correlation ID

python
import json, time, logging, os
log = logging.getLogger(); log.setLevel(os.getenv("LOG_LEVEL", "INFO"))

def emit(level, msg, ctx, **fields):
    log.info(json.dumps({"level": level, "msg": msg, "requestId": ctx.aws_request_id,
                         "function": ctx.function_name, "ts": int(time.time() * 1000), **fields}))

def handler(event, context):
    emit("INFO", "order received", context, orderId=event["orderId"], tenant=event["tenant"])

Lambda supports JSON log format natively with LoggingConfig (LogFormat: JSON, ApplicationLogLevel, SystemLogLevel), and Powertools for AWS Lambda adds structured logging, metrics and tracing helpers. Query it:

text
fields @timestamp, level, orderId, msg
| filter level = "ERROR" and tenant = "t-42"
| stats count() by bin(5m)

Choose log levels deliberately (DEBUG off in production by default), set log group retention to control cost, and never log secrets.

Custom metrics with EMF

python
print(json.dumps({
  "_aws": {"Timestamp": int(time.time()*1000),
           "CloudWatchMetrics": [{"Namespace": "Orders", "Dimensions": [["Service"]],
                                  "Metrics": [{"Name": "OrdersPlaced", "Unit": "Count"}]}]},
  "Service": "checkout", "OrdersPlaced": 1}))

Health checks and probes

ProbePurposeFailure action
LivenessIs the process stuck?Restart the container or instance
ReadinessCan it accept requests now (warm cache, DB reachable)?Remove from load balancer rotation
StartupIs a slow-starting app still initialising?Delay other probes

For ECS, define a container healthCheck and an ALB target group check; for EKS use livenessProbe and readinessProbe. Keep checks fast and cheap and avoid cascading failures where one dependency blip empties the whole fleet. Route 53 health checks and CloudWatch Synthetics canaries verify endpoints from outside.

yaml
containerDefinitions:
  - name: api
    healthCheck:
      command: ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"]
      interval: 15
      timeout: 5
      retries: 3
      startPeriod: 30

Alerts for quotas and deployments

Many incidents come from hitting a limit: Lambda concurrency, ENI or IP addresses, DynamoDB table counts, API throttles. Service Quotas publishes usage metrics for many quotas; alarm at 80 percent.

bash
aws cloudwatch put-metric-alarm --alarm-name lambda-concurrency-80 \
  --namespace AWS/Lambda --metric-name ConcurrentExecutions --statistic Maximum \
  --period 60 --evaluation-periods 3 --threshold 800 --comparison-operator GreaterThanThreshold \
  --alarm-actions arn:aws:sns:eu-west-1:111122223333:ops-alerts
aws service-quotas request-service-quota-increase --service-code lambda \
  --quota-code L-B99A9384 --desired-value 3000

Notify on deployments with an EventBridge rule:

json
{"source": ["aws.codedeploy"], "detail-type": ["CodeDeploy Deployment State-change Notification"],
 "detail": {"state": ["FAILURE", "STOP"]}}

Target an SNS topic or AWS Chatbot channel. CodePipeline and CodeBuild also support notification rules to SNS. AWS Health events warn about service issues and scheduled maintenance affecting your account.

Dashboards and insights

Build a CloudWatch dashboard per service with the golden signals: latency, traffic, errors and saturation. Add Contributor Insights to find top talkers, Lambda Insights for memory and CPU, and Logs Insights queries saved for runbooks.

Real World Example

An SRE team often learned about outages from customers. They switched services to JSON structured logs with request IDs, emitted business metrics through EMF, and created dashboards for the four golden signals. Quota alarms at 80 percent on Lambda concurrency and ENI usage caught a growth problem a week before a launch, and an EventBridge rule on CodeDeploy failures now posts to the team chat within seconds.

Architecture Diagram

Observability signals
Architecture
Observability
ServiceJSON logs + EMF
CloudWatchlogs, metrics, traces
SNS / chat
Logs Insightscorrelation ID

Logs, metrics and traces share a correlation ID and feed alerts.

  1. 1Services emit structured logs, custom metrics and traces with a correlation ID.
  2. 2CloudWatch stores the signals and evaluates alarms.
  3. 3Alarms and EventBridge rules notify the team through SNS or chat.
  4. 4Engineers pivot through Logs Insights and traces using the shared ID.

Best Practices

  • ✓Emit structured JSON logs with a correlation ID and tenant or user context.
  • ✓Use EMF for custom metrics and alarm on business and quota indicators.
  • ✓Separate liveness and readiness and keep health checks fast and shallow.
  • ✓Alarm on quota utilisation and request increases before launches.
  • ✓Notify on deployment failures through EventBridge and SNS or chat.

Common Interview Questions

Exam Tips

DVA-C02 focus

  • 'Search structured logs and aggregate' means CloudWatch Logs Insights.
  • 'Custom metric from Lambda without API calls' means Embedded Metric Format.
  • Deployment failure notification uses an EventBridge rule (or notification rules) to SNS.
  • Readiness failure removes a target from the ALB; liveness failure triggers a restart.

Finished this lesson?

0 of 46 lessons done · 0% of the course