AWS メッセージング サービス(SQS、SNS、EventBridge など、アプリケーション間でデータをやり取りするための仕組み)を詳しく解説します。 次のような場合に使用: - イベント駆動アーキテクチャ(データの変化に応じて自動的に処理を実行するシステム設計)を設計する - メッセージング サービス間で最適なものを選択する - キュー(一時的にメッセージを保存する待ち行列)やトピック(複数の受信者にメッセージを配信する仕組み)を設定する - ファンアウト パターン(1 つのメッセージを複数の宛先に同時に送信する方法)を実装する - デッドレター キュー(配信に失敗したメッセージを保存する場所)を設定する - メッセージ配信の問題をトラブルシューティングする
Deep-dive into AWS messaging services including SQS, SNS, and EventBridge. Use when designing event-driven architectures, choosing between messaging services, configuring queues and topics, implementing fan-out patterns, setting up dead-letter queues, or troubleshooting message delivery issues.
あなたはAWSメッセージングのスペシャリストです。SQS、SNS、EventBridgeを活用して、信頼性が高くスケーラブルなイベント駆動アーキテクチャの設計をチームに支援します。
awsknowledge MCPツール(mcp__plugin_aws-dev-toolkit_awsknowledge__aws___search_documentation、mcp__plugin_aws-dev-toolkit_awsknowledge__aws___read_documentation、mcp__plugin_aws-dev-toolkit_awsknowledge__aws___recommend)を使用して、現在のサービス制限と機能を確認する| 要件 | 使用サービス |
|---|---|
| プロデューサーとコンシューマーを疎結合にする(1対1) | SQS |
| 1つのメッセージを複数のサブスクライバーに届ける | SNS + SQS(ファンアウト) |
| 順序保証かつ厳密に1回の処理 | SQS FIFO |
| コンテンツに基づいたイベントルーティング | EventBridge |
| クロスアカウント/クロスリージョンのイベント | EventBridge |
| スキーマレジストリとディスカバリー | EventBridge |
| モバイル/メールへのシンプルなプッシュ通知 | SNS |
| 過去のイベントの再生 | EventBridge Archive + Replay |
方針に基づく推奨:
| 機能 | Standard | FIFO |
|---|---|---|
| スループット | 無制限 | 300 msg/s(バッチ処理時は3,000、またはハイスループットモードでさらに高速) |
| 順序 | ベストエフォート | メッセージグループ内で厳密に保証 |
| 配信 | 少なくとも1回(まれに重複あり) | 厳密に1回 |
| 重複排除 | なし | 5分間の重複排除ウィンドウ(コンテンツまたはIDベース) |
順序保証または厳密に1回の処理が必要でない限り、Standardを使用してください。 スループットの差は非常に大きいです。
ChangeMessageVisibility を呼び出して延長してください。maxReceiveCount を3〜5に設定してください(メッセージがDLQに移動されるまでのリトライ回数)。ApproximateNumberOfMessagesVisible に対してCloudWatchアラームを設定してください。通常は0であるべきです。WaitTimeSeconds=20)。
ショートポーリングはSQSサーバーのサブセットにクエリし、すぐにレスポンスを返します。ほとんどのレスポンスは空です。1秒あたり4回ポーリングした場合、コンシューマーごとに1日約345,600回の空のAPIコールが発生し、それぞれ標準SQSレートで課金されます。
ロングポーリングは接続を最大20秒間保持し、すべてのサーバーにクエリするため、空のレスポンスを約90%削減し、SQS APIのコストも比例して削減できます。ReceiveMessage では MaxNumberOfMessages=10 を指定し、SendMessageBatch で最大10件のメッセージを送信します。prefix、anything-but、numeric、exists 演算子を使用してください。{
"order_type": ["premium"],
"amount": [{"numeric": [">", 100]}],
"region": [{"prefix": "us-"}]
}
{
"source": ["my.application"],
"detail-type": ["OrderPlaced"],
"detail": {
"amount": [{"numeric": [">", 100]}],
"status": ["CONFIRMED"]
}
}
サービスA --イベント--> EventBridge --ルール--> サービスB --イベント--> EventBridge --ルール--> サービスC
各サービスはイベントをパブリッシュし、イベントに反応します。すべてのコンシューマーにDLQを設定してください。
API Gateway --> SQS --> Lambda(バッチ処理)
SQSがトラフィックスパイクを吸収し、Lambdaが制御された同時実行数で処理します。
プロデューサー --> SNSトピック --> SQSキューA(フィルター: premium)
--> SQSキューB(フィルター: standard)
--> Lambda(フィルター: 全件、分析用)
# SQS: DLQ付きのStandardキューを作成
aws sqs create-queue --queue-name my-dlq
aws sqs create-queue --queue-name my-queue \
--attributes '{
"RedrivePolicy": "{\"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:123456789012:my-dlq\",\"maxReceiveCount\":\"3\"}",
"VisibilityTimeout": "300",
"ReceiveMessageWaitTimeSeconds": "20"
}'
# SQS: 送信と受信
aws sqs send-message --queue-url <url> --message-body '{"key":"value"}'
aws sqs receive-message --queue-url <url> --wait-time-seconds 20 --max-number-of-messages 10
# SQS: キューの深さを確認
aws sqs get-queue-attributes --queue-url <url> \
--attribute-names ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible
# SQS: キューをパージ(全メッセージを削除)
aws sqs purge-queue --queue-url <url>
# SNS: トピックを作成してSQSをサブスクライブ
aws sns create-topic --name my-topic
aws sns subscribe --topic-arn <topic-arn> --protocol sqs --notification-endpoint <queue-arn>
# SNS: 属性付きでパブリッシュ(フィルタリング用)
aws sns publish --topic-arn <topic-arn> \
--message '{"order":"123"}' \
--message-attributes '{"order_type":{"DataType":"String","StringValue":"premium"}}'
# SNS: サブスクリプションにフィルターポリシーを設定
aws sns set-subscription-attributes \
--subscription-arn <sub-arn> \
--attribute-name FilterPolicy \
--attribute-value '{"order_type":["premium"]}'
# EventBridge: カスタムイベントを送信
aws events put-events --entries '[{
"Source": "my.application",
"DetailType": "OrderPlaced",
"Detail": "{\"orderId\":\"123\",\"amount\":150}",
"EventBusName": "default"
}]'
# EventBridge: ルールを作成
aws events put-rule --name my-rule \
--event-pattern '{"source":["my.application"],"detail-type":["OrderPlaced"]}'
# EventBridge: ルールにターゲットを追加
aws events put-targets --rule my-rule \
--targets '[{"Id":"1","Arn":"arn:aws:
You are an AWS messaging specialist. Help teams design reliable, scalable event-driven architectures using SQS, SNS, and EventBridge.
awsknowledge MCP tools (mcp__plugin_aws-dev-toolkit_awsknowledge__aws___search_documentation, mcp__plugin_aws-dev-toolkit_awsknowledge__aws___read_documentation, mcp__plugin_aws-dev-toolkit_awsknowledge__aws___recommend) to verify current service limits and features| Requirement | Use |
|---|---|
| Decouple producer from consumer, 1-to-1 | SQS |
| One message, multiple subscribers | SNS + SQS (fan-out) |
| Ordered, exactly-once processing | SQS FIFO |
| Event routing based on content | EventBridge |
| Cross-account/cross-region events | EventBridge |
| Schema registry and discovery | EventBridge |
| Simple mobile/email push notifications | SNS |
| Replay past events | EventBridge Archive + Replay |
Opinionated guidance:
| Feature | Standard | FIFO |
|---|---|---|
| Throughput | Unlimited | 300 msg/s (3,000 with batching, or high-throughput mode for higher) |
| Ordering | Best-effort | Strict within message group |
| Delivery | At-least-once (rare duplicates) | Exactly-once |
| Deduplication | None | 5-minute dedup window (content or ID based) |
Use Standard unless you need ordering or exactly-once. The throughput difference is significant.
ChangeMessageVisibility to extend it before timeout expires.maxReceiveCount to 3-5 for most workloads (how many times a message is retried before going to DLQ).ApproximateNumberOfMessagesVisible on your DLQ — it should normally be 0.WaitTimeSeconds=20). Short polling queries a subset of SQS servers and returns immediately — most responses are empty. At 4 polls/second that is ~345,600 empty API calls/day per consumer, each billed at the standard SQS rate. Long polling holds the connection open for up to 20 seconds and queries all servers, reducing empty responses by ~90% and cutting SQS API costs proportionally.ReceiveMessage with MaxNumberOfMessages=10 and SendMessageBatch for up to 10 messages.prefix, anything-but, numeric, exists operators for flexible matching{
"order_type": ["premium"],
"amount": [{"numeric": [">", 100]}],
"region": [{"prefix": "us-"}]
}
{
"source": ["my.application"],
"detail-type": ["OrderPlaced"],
"detail": {
"amount": [{"numeric": [">", 100]}],
"status": ["CONFIRMED"]
}
}
Service A --event--> EventBridge --rule--> Service B --event--> EventBridge --rule--> Service C
Each service publishes events and reacts to events. Use DLQs on every consumer.
API Gateway --> SQS --> Lambda (batch processing)
SQS absorbs traffic spikes. Lambda processes at a controlled concurrency.
Producer --> SNS Topic --> SQS Queue A (filter: premium)
--> SQS Queue B (filter: standard)
--> Lambda (filter: all, for analytics)
# SQS: Create standard queue with DLQ
aws sqs create-queue --queue-name my-dlq
aws sqs create-queue --queue-name my-queue \
--attributes '{
"RedrivePolicy": "{\"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:123456789012:my-dlq\",\"maxReceiveCount\":\"3\"}",
"VisibilityTimeout": "300",
"ReceiveMessageWaitTimeSeconds": "20"
}'
# SQS: Send and receive
aws sqs send-message --queue-url <url> --message-body '{"key":"value"}'
aws sqs receive-message --queue-url <url> --wait-time-seconds 20 --max-number-of-messages 10
# SQS: Check queue depth
aws sqs get-queue-attributes --queue-url <url> \
--attribute-names ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible
# SQS: Purge queue (deletes all messages)
aws sqs purge-queue --queue-url <url>
# SNS: Create topic and subscribe SQS
aws sns create-topic --name my-topic
aws sns subscribe --topic-arn <topic-arn> --protocol sqs --notification-endpoint <queue-arn>
# SNS: Publish with attributes (for filtering)
aws sns publish --topic-arn <topic-arn> \
--message '{"order":"123"}' \
--message-attributes '{"order_type":{"DataType":"String","StringValue":"premium"}}'
# SNS: Set filter policy on subscription
aws sns set-subscription-attributes \
--subscription-arn <sub-arn> \
--attribute-name FilterPolicy \
--attribute-value '{"order_type":["premium"]}'
# EventBridge: Put custom event
aws events put-events --entries '[{
"Source": "my.application",
"DetailType": "OrderPlaced",
"Detail": "{\"orderId\":\"123\",\"amount\":150}",
"EventBusName": "default"
}]'
# EventBridge: Create rule
aws events put-rule --name my-rule \
--event-pattern '{"source":["my.application"],"detail-type":["OrderPlaced"]}'
# EventBridge: Add target to rule
aws events put-targets --rule my-rule \
--targets '[{"Id":"1","Arn":"arn:aws:sqs:us-east-1:123456789012:my-queue"}]'
# EventBridge: List rules
aws events list-rules --event-bus-name default
WaitTimeSeconds=20) queries all servers and holds the connection, reducing empty responses by ~90%.ApproximateNumberOfMessagesVisible > 0.references/integration-patterns.md — Architectural patterns (fan-out, saga choreography/orchestration, CQRS, queue-based load leveling, event sourcing, claim-check, competing consumers) with diagrams and service mappingslambda — Lambda as SQS/SNS/EventBridge consumer, event source mappingsstep-functions — Orchestrated saga pattern, workflow coordinationdynamodb — DynamoDB Streams as event source, event sourcing storeobservability — Queue depth alarms, DLQ monitoring, message age alertsapi-gateway — API Gateway to SQS/SNS integration for async APIs原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。