0Pricing
Serverless Backend with AWS Lambda & API Gateway · レッスン

デッドレターキューと障害処理

メッセージの処理に失敗することはあります。デッドレターキューで問題のあるメッセージを捕捉し、レジリエントなイベント駆動システムのためにリトライと再処理を設計する方法を学びます。

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

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

The Problem of Failing Messages

In an event-driven system a message may fail repeatedly — bad data, a downstream outage, or a bug. Without a safety net, it can block the queue or be lost forever.

What is a Dead-Letter Queue?

A dead-letter queue (DLQ) is a separate queue that captures messages that could not be processed after a set number of attempts. This isolates poison messages without losing them.

Redrive Policy

An SQS queue routes to a DLQ via a redrive policy that names the DLQ and a maxReceiveCount. After that many failed receives, the message moves to the DLQ.

{
  "deadLetterTargetArn": "arn:aws:sqs:us-east-1:123:orders-dlq",
  "maxReceiveCount": 5
}

Configuring a DLQ for Lambda

Async Lambda invocations (S3, SNS) can send failures to a DLQ or to an on-failure destination via the event invoke config.

aws lambda put-function-event-invoke-config \
  --function-name processOrder \
  --destination-config '{"OnFailure":{"Destination":"arn:aws:sqs:...:orders-dlq"}}'

Setting maxReceiveCount Wisely

Too low and transient blips dead-letter good messages; too high and a poison message wastes many retries. A value of 3 to 5 is a common starting point.

Inspecting Dead-Lettered Messages

Messages in the DLQ keep the original body plus attributes showing why they failed. Read them to diagnose the root cause before reprocessing.

aws sqs receive-message \
  --queue-url https://sqs.../orders-dlq \
  --attribute-names All

Redriving Messages Back

Once the bug is fixed, SQS can redrive messages from the DLQ back to the source queue for reprocessing — no manual copying needed.

Idempotency Matters

Because retries and redrives can deliver the same message more than once, your handler must be idempotent: processing the same message twice should not double-charge or duplicate records.

Alerting on the DLQ

A growing DLQ is a signal something is broken. Set a CloudWatch alarm on the DLQ ApproximateNumberOfMessagesVisible metric to get notified.

Partial Batch Failures

When Lambda reads a batch from SQS, reporting batchItemFailures lets only the failed messages return to the queue, instead of reprocessing the whole batch.

{
  "batchItemFailures": [
    { "itemIdentifier": "msg-id-3" }
  ]
}

Designing for Resilience

A resilient pipeline combines:

  • Retries for transient errors
  • A DLQ for poison messages
  • Idempotent handlers
  • Alarms and a redrive plan

Quick Check

Test your failure-handling knowledge.

Recap

You learned to handle failing messages:

  • A DLQ isolates poison messages after maxReceiveCount
  • Configure redrive policies and Lambda on-failure destinations
  • Inspect, fix, then redrive messages back
  • Make handlers idempotent and alarm on DLQ depth
  • Use batchItemFailures for partial batch retries

よくある質問

「デッドレターキューと障害処理」レッスンは無料ですか?

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

「デッドレターキューと障害処理」で何を学びますか?

メッセージの処理に失敗することはあります。デッドレターキューで問題のあるメッセージを捕捉し、レジリエントなイベント駆動システムのためにリトライと再処理を設計する方法を学びます。 ブラウザで直接実行するハンズオンコードでServerless Backend with AWS Lambda & API Gatewayを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Serverless Backend with AWS Lambda & API Gatewayを始めるのに経験は必要ですか?

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

「デッドレターキューと障害処理」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. サービスの疎結合化に使うSQS
  2. Pub/Subメッセージングに使うSNS
  3. SQS/SNSトリガーでLambdaを実行
  4. デッドレターキューと障害処理
← Serverless Backend with AWS Lambda & API Gatewayに戻る