0Pricing
Serverless AWS Lambda Development · レッスン

カスタムメトリクスとCloudWatchアラーム

Lambdaから独自のビジネス指標やパフォーマンスメトリクスを出力し、しきい値を超えたときにアラームや通知を発生させる方法を学びます。

「カスタムメトリクスとCloudWatchアラーム」はCoddyKit上の無料Serverless AWS Lambda Developmentレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはServerless AWS Lambda Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Serverless AWS Lambda Developmentコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Beyond Default Metrics

Lambda publishes built-in metrics like invocations and errors, but your app has its own signals, such as orders processed or items failed. These are custom metrics.

Embedded Metric Format

The easiest way to emit metrics is the Embedded Metric Format (EMF): print structured JSON to logs and CloudWatch extracts metrics automatically.

{
  "_aws": {
    "CloudWatchMetrics": [{
      "Namespace": "OrdersApp",
      "Metrics": [{"Name": "OrdersProcessed", "Unit": "Count"}]
    }]
  },
  "OrdersProcessed": 12
}

Emitting EMF in Python

Build the EMF object and print it as JSON. No extra API call or latency is needed.

import json, time

def emit(count):
    print(json.dumps({
        '_aws': {
            'Timestamp': int(time.time() * 1000),
            'CloudWatchMetrics': [{
                'Namespace': 'OrdersApp',
                'Dimensions': [[]],
                'Metrics': [{'Name': 'OrdersProcessed', 'Unit': 'Count'}]
            }]
        },
        'OrdersProcessed': count
    }))

PutMetricData API

Alternatively call put_metric_data directly. This is synchronous and adds latency, so EMF is usually preferred for hot paths.

import boto3
cw = boto3.client('cloudwatch')
cw.put_metric_data(Namespace='OrdersApp',
  MetricData=[{'MetricName': 'OrdersProcessed', 'Value': 1}])

Dimensions Add Context

Dimensions are key-value tags that slice a metric, such as by region or customer tier. Keep dimension cardinality low to control cost.

What an Alarm Does

A CloudWatch alarm watches a metric and changes state when it breaches a threshold for a set number of periods, then triggers an action.

Creating an Alarm

This alarm fires when the error count exceeds 5 in a single one-minute period.

aws cloudwatch put-metric-alarm \
  --alarm-name orders-errors \
  --metric-name Errors \
  --namespace AWS/Lambda \
  --threshold 5 \
  --comparison-operator GreaterThanThreshold \
  --evaluation-periods 1 \
  --period 60

Notifying with SNS

Point the alarm action at an SNS topic so it emails, texts, or pages your on-call when triggered.

Alarm States

Alarms have three states: OK, ALARM, and INSUFFICIENT_DATA. The last means the metric had no data points in the window.

Avoid Alarm Fatigue

Too many noisy alarms train people to ignore them. Alarm on symptoms users feel, like error rate and latency, not every minor metric.

Dashboards Tie It Together

Build a CloudWatch dashboard combining built-in and custom metrics so you see the whole system health at a glance during an incident.

Quick Check

Test your metrics knowledge.

Recap

You learned to emit custom metrics via EMF or PutMetricData, add dimensions, create threshold alarms wired to SNS, and avoid alarm fatigue with dashboards.

よくある質問

「カスタムメトリクスとCloudWatchアラーム」レッスンは無料ですか?

はい。「カスタムメトリクスとCloudWatchアラーム」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Serverless AWS Lambda Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Serverless AWS Lambda Developmentコースには全4レッスンが含まれています。

「カスタムメトリクスとCloudWatchアラーム」で何を学びますか?

Lambdaから独自のビジネス指標やパフォーマンスメトリクスを出力し、しきい値を超えたときにアラームや通知を発生させる方法を学びます。 ブラウザで直接実行するハンズオンコードでServerless AWS Lambda Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Serverless AWS Lambda Developmentを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのServerless AWS Lambda Developmentは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「カスタムメトリクスとCloudWatchアラーム」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このServerless AWS Lambda Developmentレッスンでコードを書いて実行できますか?

はい。すべてのServerless AWS Lambda Developmentレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. CloudWatchのログとメトリクス
  2. エラーハンドリングとリトライ
  3. サーバーレスアプリケーションのデバッグ
  4. カスタムメトリクスとCloudWatchアラーム
← Serverless AWS Lambda Developmentに戻る