BrainyBeeBrainyBee
ExploreBlogStart Studying
HomeAWS Certified Developer - Associate (DVA-C02)Implementing Custom Metrics in AWS Applications
Study Guide845 words

Implementing Custom Metrics in AWS Applications

Implement code that emits custom metrics

Implementing Custom Metrics in AWS Applications

Monitoring application-specific behavior is a core requirement for the AWS Certified Developer - Associate (DVA-C02) exam. While AWS provides default metrics (e.g., CPU utilization, disk I/O), custom metrics allow developers to track business-level data like 'Items Sold', 'Cache Misses', or 'User Login Latency'.

Learning Objectives

By the end of this guide, you will be able to:

  • Differentiate between standard metrics and custom metrics.
  • Implement code using the PutMetricData API.
  • Use the CloudWatch Embedded Metric Format (EMF) for high-performance metric emission.
  • Define and manage metric dimensions to balance granularity and cost.
  • Understand metric resolution and its impact on monitoring.

Key Terms & Glossary

  • Namespace: A container for CloudWatch metrics. You must provide a namespace when you create a custom metric (e.g., MyCompany/PaymentService).
  • Dimension: A name/value pair that is part of the identity of a metric. Adding dimensions helps you filter results (e.g., Environment=Production).
  • Resolution: Defines the granularity of data points. Standard resolution is 1 minute; high resolution is 1 second.
  • Embedded Metric Format (EMF): A JSON specification used to instruct CloudWatch Logs to automatically extract metric data from log streams.
  • Cardinality: The number of unique combinations of dimensions. High cardinality can lead to increased costs.

The "Big Idea"

The "Big Idea" behind custom metrics is observability beyond infrastructure. Standard metrics tell you if the server is healthy, but custom metrics tell you if the application is healthy. By emitting metrics directly from your code, you close the gap between resource performance and business logic success.

Formula / Concept Box

FeaturePutMetricData (SDK)Embedded Metric Format (EMF)
MechanismSynchronous HTTP API CallAsynchronous via CloudWatch Logs
ThroughputLimited by API Throttling (150 tps)High (limited only by log ingestion)
CostCharged per API callNo API charge for metrics (charged for logs)
Use CaseLow frequency, simple scriptsHigh throughput, Lambda functions

Hierarchical Outline

  1. Metric Definition Elements
    • MetricName: The specific name (e.g., OrderCount).
    • Unit: The type of value (e.g., Seconds, Bytes, Count, Percent).
    • Value: The numeric data point.
  2. The SDK Approach (PutMetricData)
    • Best for real-time tracking of specific events.
    • Requires handling retries and batching.
    • Limits: Maximum 20 metrics per call; maximum 150 requests per second.
  3. The Log-Based Approach (EMF)
    • Preferred for AWS Lambda to avoid blocking execution.
    • Requires structured JSON in a specific format.
    • Automatically processed by CloudWatch backend.

Visual Anchors

Metric Delivery Architecture

Loading Diagram...

Anatomy of a Metric Structure

Compiling TikZ diagram…
⏳
Running TeX engine…
This may take a few seconds

Definition-Example Pairs

  • Dimension: A label to categorize data. Example: In a billing app, you might use a dimension PaymentType=CreditCard to see if credit card processing is slower than other methods.
  • High-Resolution Metric: Metrics stored with 1-second granularity. Example: During a flash sale, you monitor TransactionVolume at high resolution to detect sub-minute spikes that could crash the DB.
  • Metric Batching: Sending multiple data points in one API call. Example: Accumulating 20 different success/failure counts in memory and sending them once every minute to reduce PutMetricData costs.

Worked Examples

Example 1: Emitting a Metric with Python (boto3)

This example shows a synchronous call to track the number of processed files.

python
import boto3 cloudwatch = boto3.client('cloudwatch') cloudwatch.put_metric_data( Namespace='App/FileProcessor', MetricData=[ { 'MetricName': 'FilesProcessed', 'Dimensions': [ {'Name': 'Environment', 'Value': 'Production'}, {'Name': 'Type', 'Value': 'PDF'} ], 'Value': 1.0, 'Unit': 'Count', 'StorageResolution': 60 } ] )

Example 2: EMF JSON Format (Manual)

If you aren't using the EMF library, you can simply print this JSON to stdout in a Lambda function.

json
{ "_aws": { "Timestamp": 1615553000000, "CloudWatchMetrics": [ { "Namespace": "App/LambdaNode", "Dimensions": [["FunctionName"]], "Metrics": [{"Name": "ProcessingTime", "Unit": "Milliseconds"}] } ] }, "FunctionName": "processOrder", "ProcessingTime": 45 }

Checkpoint Questions

  1. What is the maximum number of metrics you can include in a single PutMetricData call?
  2. Why is EMF preferred over PutMetricData for AWS Lambda functions?
  3. What happens to the resolution if you omit the StorageResolution parameter in your code?
  4. How does CloudWatch distinguish between the same MetricName that has different Dimensions?

[!TIP] Answer Key:

  1. 20 metrics.
  2. It is asynchronous and doesn't introduce network latency to the function execution.
  3. It defaults to standard resolution (60 seconds).
  4. It treats them as unique metrics; a metric is defined by its name AND its dimensions.
All AWS Certified Developer - Associate (DVA-C02) Study Resources

Related Notes

  • AWS X-Ray: Mastering Annotations and Metadata for Service Tracing864 words
  • Mastering Application Performance Analysis: AWS DVA-C02 Study Guide945 words
  • Optimizing Application Resource Requirements1,050 words
  • Mastering Root Cause Analysis: AWS Developer Associate Study Guide985 words
  • Root Cause Analysis Mastery: Debugging Serverless Applications on AWS920 words
  • Mastering IAM Role Assumption & AWS STS865 words
  • Automating Deployment Testing in AWS865 words
  • Lab: Automating Deployment Testing with AWS CI/CD and SAM920 words
  • AWS CloudFront: Caching Content Based on Request Headers1,150 words
  • Study Guide: Committing Code to Invoke Automated CI/CD Pipelines895 words
  • Mastering Application Health Checks and Readiness Probes985 words
  • AWS Deployment Strategies: Blue/Green, Canary, and Rolling Releases945 words

Ready to study AWS Certified Developer - Associate (DVA-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up.

Start Studying

Ready to study AWS Certified Developer - Associate (DVA-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free
AWS Certified Developer - Associate (DVA-C02) ResourcesExplore All HivesBlogHome

© 2026 BrainyBee. Free AI-powered exam prep.