📨aws-messaging-and-streaming
- プラグイン
- aws-core
- ソース
- GitHub で見る ↗
説明
AWSのメッセージングおよびストリーミングサービスの利用をガイドします。 対象サービスは以下の通りです:Amazon SQS、Amazon SNS、Amazon EventBridge、Amazon MQ、Amazon Kinesis Data Streams、Amazon Data Firehose、Amazon Managed Service for Apache Flink、Amazon Managed Streaming for Apache Kafka(MSK)。 次のような場合に使用: メッセージングおよびストリーミングのパターンを実装する際。
原文を表示
Guides use of AWS messaging and streaming services. Covers Amazon SQS, Amazon SNS, Amazon EventBridge, Amazon MQ, Amazon Kinesis Data Streams, Amazon Data Firehose, Amazon Managed Service for Apache Flink, and Amazon Managed Streaming for Apache Kafka (MSK). Use when implementing messaging and streaming patterns.
ユースケース
- ✓メッセージングパターンを実装するとき
- ✓ストリーミングパターンを実装するとき
- ✓AWSのメッセージング・ストリーミングサービスを選定する場面
本文(日本語訳)
AWS メッセージング & ストリーミングサービス
AWSのメッセージング・ストリーミングに関する質問に回答する際は、具体的な数値・バージョン・制限値・動作の詳細について、サービス固有のSkillや公式AWSドキュメントで必ず確認してください。 不確かな場合は推測せず、Skillまたはドキュメントを検索してください。 設定オプションの捏造や不正確なバージョン番号は、不確かさを認めるよりも有害です。
推奨設定(CloudWatchアラームの設定、閾値、データ欠損時の扱いなど)について質問があった場合も、一般的なベストプラクティスに頼らず、サービス固有のSkillまたはドキュメントを検索してください。
概要
プロデューサーとコンシューマー間でデータを移動させるAWSサービスの選択・活用に関するドメイン知識です。 このSkillは、メッセージングとストリーミングという2つの基本パターン、およびそれぞれを実装するAWSサービスをカバーします。 ワークロードにどちらのパターンが適しているかの判断、適切なサービスの選定、サービス間の連携方法の理解にこのSkillを活用してください。
個別のAWSサービスに関する詳細なガイダンスは、リファレンスファイルまたはサービス固有のSkillを参照してください。
ストリーミングとメッセージング
メッセージングとは
メッセージングは、コンポーネント間の疎結合・非同期通信を実現します。 プロデューサーがメッセージを送信し、1つ以上のコンシューマーがそれを受信して処理します。 処理が完了したメッセージは通常削除されます。 メッセージングサービスは、配信保証・リトライ・デッドレターへのルーティングを担います。
主な特徴:
- メッセージはポイント・ツー・ポイント(1対1)またはファンアウト(pub/sub)で消費された後、削除される
- リプレイ不可 — 確認応答(ACK)されたメッセージは消滅する
- コマンド/リクエスト型ワークロード、タスク分散、イベント通知向けに設計されている
ストリーミングとは
ストリーミングは、順序保証・耐久性・高スループットの継続的なデータフローを実現します。 プロデューサーがログにレコードを追記し、コンシューマーはそのログ上の任意の位置から読み取ります。 レコードは消費状況に関わらず、設定された保持期間にわたって永続化されます。
主な特徴:
- レコードは保持期間内で保存され、リプレイ可能
- パーティション/シャード内で厳密な順序保証
- 複数の独立したコンシューマーが異なる位置から同じデータを読み取れる
- イベントソーシング、リアルタイム分析、チェンジデータキャプチャ(CDC)、継続的処理向けに設計されている
主な違い
| 比較軸 | メッセージング | ストリーミング |
|---|---|---|
| データのライフサイクル | 消費後に削除 | リプレイのために保持(時間〜無期限) |
| 順序保証 | ベストエフォート(Standard)またはグループ単位(FIFO) | パーティション/シャード単位で厳密に保証 |
| コンシューマーモデル | 競合コンシューマー(ワーク分散) | 独立したリーダー(位置によるファンアウト) |
| スループットパターン | バースト的・変動的 | 持続的・大容量 |
| リプレイ | 非対応(DLQの再ドライブを除く) | ネイティブ対応 — 保持期間内の任意位置にシーク可能 |
| 一般的なレイテンシ | ミリ秒(プッシュまたはショートポーリング) | ミリ秒〜低秒数 |
| スケーリング単位 | 同時実行数(コンシューマー/ポーラー) | パーティションまたはシャード |
メッセージングのユースケース
- リクエスト/レスポンスまたはコマンドパターンによるマイクロサービスの疎結合化
- 競合コンシューマーのプールへのワーク分散(タスクキュー)
- 各サブスクライバーが独立して動作するファンアウト通知
- バースト的でキューバッファリングの恩恵を受けるワークロード
- 既存のJMS/AMQPアプリケーションの移行(Amazon MQ)
ストリーミングのユースケース
- 継続的・高スループットなデータ取り込み(ログ、メトリクス、クリックストリーム、IoTテレメトリ)
- 任意の時点からリプレイが必要なイベントソーシング
- 同一データを異なる方法で処理する複数の独立したコンシューマー
- リアルタイム分析、ウィンドウ集計、複合イベント処理
- チェンジデータキャプチャ(CDC)パイプライン
メッセージングサービス
以下のサービスは一般的にメッセージングワークロードに使用されます。 ユースケースや要件によっては、ストリーミングサービス(Kinesis Data Streams、Amazon MSK)がメッセージングワークロードに使われることもあります。
| サービス | 最適な用途 | 主な差別化ポイント |
|---|---|---|
| Amazon SQS | タスクキュー、疎結合化、バッファリング | フルマネージド、無制限スループット(Standard)、exactly-once配信(FIFO)、マルチテナントワークロード向けフェアキュー |
| Amazon SNS | ファンアウト、pub/sub通知 | 複数サブスクライバー(SQS、Lambda、HTTP、メール、SMS)へのプッシュ配信 |
| Amazon EventBridge | イベントルーティング、クロスアカウント/SaaS連携 | コンテンツベースフィルタリング、スキーマレジストリ、200以上のAWSソースとの統合 |
| Amazon MQ | 既存JMS/AMQP/MQTTアプリのリフト&シフト | レガシー移行向けプロトコル互換性(ActiveMQ、RabbitMQ) |
ストリーミングサービス
以下のサービスは一般的にストリーミングワークロードに使用されます。
| サービス | 最適な用途 | 主な差別化ポイント |
|---|---|---|
| Amazon Kinesis Data Streams | AWSネイティブコンシューマーを用いたリアルタイム取り込み | オンデマンドAdvantageモード(即時スケーリング、シャード管理不要)、1〜365日間の保持 |
| Amazon Data Firehose | ストレージ/分析基盤への管理不要な配信 | 自動スケーリング、バッファリング、バッチ処理、デスティネーションへの配信 |
| Amazon Managed Service for Apache Flink | 複雑なストリーム処理(ジョイン、ウィンドウ、ステート管理) | フルApache Flinkランタイム — ステートフル処理向けSQL・Java・Python API |
| Amazon MSK | Kafkaネイティブワークロード、エコシステム互換性 | Apache Kafka API、Expressブローカー(Standardブローカー比3倍のスループット・20倍高速なスケーリング)、豊富なコネクターエコシステム |
よくある統合上の落とし穴
-
SQSのシステム属性とユーザーメッセージ属性の違い:
AWSTraceHeader(X-Ray / EventBridge / PipesがSQS DLQへ送信する際に付与)、SenderId、SentTimestampなどの属性はSQSのシステム属性であり、ユーザーメッセージ属性ではありません。 これらはReceiveMessageのデフォルトレスポンスには含まれないため、AttributeNames=[...](またはMessageSystemAttributeNames)で明示的にリクエストする必要があります。 ユーザー属性を取得するMessageAttributeNamesとは別物です。 DLQではトレースヘッダーがシステム属性に載り、ユーザー属性スロットにはサービスの障害メタデータ(例: EventBridgeのRULE_ARN、ERROR_CODE)が含まれるため、この区別は特に重要です。 -
SNS → Firehose → S3 のレコード区切り文字:
firehoseプロトコルを使用するSNSサブスクリプションでS3に書き込む場合、レコードはデフォルトで既に改行区切り(NDJSON)になっています。 FirehoseのAppendDelimiterToRecordは有効にしないでください — SNS自身が改行を出力するため、このプロセッサを有効にすると二重改行が発生します。 -
EventBridgeルールターゲットのDLQとSNSサブスクリプションのDLQは、いずれもDLQのキューポリシーが必要: DLQをアタッチするだけでは不十分です。キューポリシーでサービスプリンシパルを許可するまで、DLQはメッセージをサイレントにドロップします。 EventBridgeの場合:
PutTargetsでDeadLetterConfig.Arn=<DLQ>を設定し、SQSポリシーでService: events.amazonaws.comに対してsqs:SendMessageをaws:SourceArn=ルールARN の条件付きで許可。 SNSの場合:SetSubscriptionAttributesでRedrivePolicy={"deadLetterTargetArn":"<DLQ>"}を設定し、SQSポリシーでトピックARNをスコープとしてService: sns.amazonaws.comを許可。 -
SQS本番環境のデフォルト設定: ロングポーリング + カスタマーマネージド暗号化: 新規キューはデフォルトでショートポーリング(
ReceiveMessageWaitTimeSeconds=0)およびSSE-SQS(AWS管理キー)となっています。 本番環境では、SetQueueAttributesでReceiveMessageWaitTimeSeconds=20(ロングポーリング)を設定し、alias/aws/sqsのままにせずカスタマーマネージドキーのID/ARNをKmsMasterKeyIdに指定してください。 -
ブローカーおよびKafkaの認証情報はSecrets Managerに格納し、接続文字列に含めない: ユーザー名・パスワード・SASL/SCRAM認証情報を、アプリケーション設定・環境変数・JAASファイル・IaCにハードコードしないでください。 Amazon MQ(ActiveMQ/RabbitMQ)の場合は、ブローカーのユーザー情報をシークレットとして保存し起動時に取得してください。LambdaのAmazon MQイベントソースマッピングでは、ブローカー認証情報をインラインではなくSecrets ManagerのシークレットARN(
BASIC_AUTH)として指定する必要があります。 MSK SASL/SCRAMの場合、シークレットの使用は任意ではありません。シークレット名はAmazonMSK_プレフィックスで始まり、カスタマーマネージド KMSキーで暗号化されている必要があります(デフォルトのaws/secretsmanagerキーで作成されたシークレットはクラスターに関連付けできません)。その後BatchAssociateScramSecretでアタッチしてください。 MSK(SASL/SCRAMまたはmTLS)およびセルフマネージドKafka向けLambdaイベントソースマッピングも、認証情報をインラインではなくSecrets ManagerのシークレットARNで参照します。 ローテーションを有効にし、secretsmanager:GetSecretValueのIAM読み取りアクセスは利用するロールのみに限定してください。 AWS Well-Architected の SEC02-BP03 Store and use secrets securely も参照してください。 -
サービスプリンシパルのリソースポリシーには
aws:SourceArn/aws:SourceAccount条件が必要: キューやトピックのポリシーでevents.amazonaws.com、sns.amazonaws.com、s3.amazonaws.comなどのサービスプリンシパルにsqs:SendMessageやsns:Publishの権限を付与する際、送信元条件を省略すると「混乱した代理人(confused deputy)」の脆弱性が生まれます — 任意のAWSアカウントの任意のルール・トピック・バケットから書き込みが可能になってしまいます。 すべてのそのようなステートメントに対して、aws:SourceArn(特定のルール/トピック/バケット/パイプのARN。ARNが完
原文(English)を表示
AWS Messaging & Streaming Services
When answering AWS messaging and streaming questions, verify specific numbers, versions, limits, and behavioral details from service-specific skills or official AWS documentation. When uncertain, search skills or docs rather than guessing. Fabricated configuration options or incorrect version numbers are worse than admitting uncertainty.
When a question asks about recommended configurations (CloudWatch alarm settings, thresholds, missing data treatment), search for the service-specific skills or documentation rather than relying on general best practices.
Overview
Domain expertise for choosing and using AWS services that move data between producers and consumers. This skill covers two fundamental patterns — messaging and streaming — and the AWS services that implement each. Use this skill to decide which pattern fits a workload, select the right service, and understand how services integrate with each other.
For specific guidance on individual AWS services, see reference files or service-specific Skills.
Streaming and Messaging
What Is Messaging?
Messaging enables decoupled, asynchronous communication between components. A producer sends a message; one or more consumers receive and process it. Once processed, the message is typically deleted. Messaging services handle delivery guarantees, retries, and dead-letter routing.
Key characteristics:
- Messages are consumed once (point-to-point) or fanned out (pub/sub), then removed
- No replay — once acknowledged, a message is gone
- Designed for command/request workloads, task distribution, and event notification
What Is Streaming?
Streaming enables ordered, durable, high-throughput continuous data flow. Producers append records to a log; consumers read from positions in that log. Records persist for a configurable retention period regardless of consumption.
Key characteristics:
- Records are retained and replayable within the retention window
- Strict ordering within a partition/shard
- Multiple independent consumers can read the same data at different positions
- Designed for event sourcing, real-time analytics, change data capture, and continuous processing
Key Differences
| Dimension | Messaging | Streaming |
|---|---|---|
| Data lifecycle | Deleted after consumption | Retained for replay (hours to indefinitely) |
| Ordering | Best-effort (Standard) or per-group (FIFO) | Strict per-partition/shard |
| Consumer model | Competing consumers (work distribution) | Independent readers (fan-out by position) |
| Throughput pattern | Bursty, variable | Sustained, high-volume |
| Replay | Not supported (except DLQ redrive) | Native — seek to any position in retention |
| Typical latency | Milliseconds (push or short-poll) | Milliseconds to low seconds |
| Scaling unit | Concurrency (consumers/pollers) | Partitions or shards |
Messaging Use Cases
- Decoupling microservices with request/response or command patterns
- Distributing work across a pool of competing consumers (task queues)
- Fan-out notifications where each subscriber acts independently
- Workloads that are bursty and benefit from queue buffering
- Migrating existing JMS/AMQP applications (Amazon MQ)
Streaming Use Cases
- Continuous, high-throughput data ingestion (logs, metrics, clickstreams, IoT telemetry)
- Event sourcing where consumers need to replay from any point in time
- Multiple independent consumers processing the same data differently
- Real-time analytics, windowed aggregations, or complex event processing
- Change data capture (CDC) pipelines
Messaging Services
These services are generally used for messaging workloads. Sometimes streaming services (Kinesis Data Streams, Managed Streaming for Apache Kafka) are also used for messaging workloads, depending on exact use case and requirements.
| Service | Best For | Key Differentiator |
|---|---|---|
| Amazon SQS | Task queues, decoupling, buffering | Fully managed, unlimited throughput (Standard), exactly-once (FIFO), fair queues for multi-tenant workloads |
| Amazon SNS | Fan-out, pub/sub notifications | Push to multiple subscribers (SQS, Lambda, HTTP, email, SMS) |
| Amazon EventBridge | Event routing, cross-account/SaaS integration | Content-based filtering, schema registry, 200+ AWS source integrations |
| Amazon MQ | Lift-and-shift of existing JMS/AMQP/MQTT apps | Protocol compatibility (ActiveMQ, RabbitMQ) for legacy migration |
Streaming Services
These services are generally used for streaming workloads.
| Service | Best For | Key Differentiator |
|---|---|---|
| Amazon Kinesis Data Streams | Real-time ingestion with AWS-native consumers | On-demand Advantage mode (instant scaling, no shard management), 1–365 day retention |
| Amazon Data Firehose | Zero-admin delivery to storage/analytics | Auto-scales, buffers, batches, and delivers to destinations |
| Amazon Managed Service for Apache Flink | Complex stream processing (joins, windows, state) | Full Apache Flink runtime — SQL, Java, Python APIs for stateful computation |
| Amazon MSK | Kafka-native workloads, ecosystem compatibility | Apache Kafka API, Express brokers (3x throughput, 20x faster scaling compared to Standard brokers), broad connector ecosystem |
Common Integration Gotchas
-
SQS system vs. user message attributes: Attributes like
AWSTraceHeader(set by X-Ray / EventBridge / Pipes when sending to an SQS DLQ) andSenderId,SentTimestampare SQS system attributes, NOT user message attributes. They are never returned by default fromReceiveMessage— request them explicitly viaAttributeNames=[...](orMessageSystemAttributeNames), separate fromMessageAttributeNameswhich fetches user attributes. This matters for DLQs, where the trace header rides on the system attribute and the user-attributes slot carries the service's failure metadata (e.g. EventBridge'sRULE_ARN,ERROR_CODE). -
SNS → Firehose → S3 record separator: For SNS subscriptions using the
firehoseprotocol that land in S3, records are already newline-delimited by default (NDJSON). Do NOT turn on Firehose'sAppendDelimiterToRecord— SNS emits the newline itself, and enabling the processor produces double newlines. -
EventBridge rule target DLQ + SNS subscription DLQ both need a DLQ queue policy. Attaching the DLQ alone is not enough — the DLQ silently drops messages until its queue policy allows the service principal. EventBridge:
PutTargetswithDeadLetterConfig.Arn=<DLQ>, plus SQS policyAllow sqs:SendMessageforService: events.amazonaws.comwithaws:SourceArn= the rule ARN. SNS:SetSubscriptionAttributesRedrivePolicy={"deadLetterTargetArn":"<DLQ>"}, plus SQS policy allowingService: sns.amazonaws.comscoped by the topic ARN. -
SQS production defaults: long polling + customer-managed encryption. New queues default to short-poll (
ReceiveMessageWaitTimeSeconds=0) and SSE-SQS (AWS-owned key). For production,SetQueueAttributeswithReceiveMessageWaitTimeSeconds=20(long polling) andKmsMasterKeyId=<customer-managed key id/ARN>rather than leavingalias/aws/sqs. -
Broker and Kafka credentials belong in Secrets Manager, not connection strings. Do not hardcode usernames, passwords, or SASL/SCRAM credentials in application config, env vars, JAAS files, or IaC. For Amazon MQ (ActiveMQ/RabbitMQ) store broker users as secrets and fetch at startup; Lambda event source mappings for Amazon MQ require the broker credentials to be supplied as a Secrets Manager secret ARN (
BASIC_AUTH), not inline. For MSK SASL/SCRAM the secret is not optional: it must be named with theAmazonMSK_prefix and encrypted with a customer-managed KMS key (secrets created with the defaultaws/secretsmanagerkey cannot be associated with a cluster), then attached viaBatchAssociateScramSecret. Lambda event source mappings for MSK (SASL/SCRAM or mTLS) and self-managed Kafka also reference a Secrets Manager secret ARN rather than inline credentials. Enable rotation and scope IAM read access (secretsmanager:GetSecretValue) to the consuming role only. See AWS Well-Architected SEC02-BP03 Store and use secrets securely. -
Service-principal resource policies need
aws:SourceArn/aws:SourceAccountconditions. When a queue or topic policy grants a service principal likeevents.amazonaws.com,sns.amazonaws.com, ors3.amazonaws.compermission tosqs:SendMessageorsns:Publish, omitting source conditions opens a confused-deputy hole — any rule, topic, or bucket in any AWS account can drive writes. Scope every such statement withaws:SourceArn(the specific rule/topic/bucket/pipe ARN; useArnLikewith*when the ARN isn't fully known yet) andaws:SourceAccount(your account ID). For S3 event notifications both keys are required because S3 bucket ARNs don't carry the account ID, soaws:SourceArnalone doesn't constrain the account. The same pattern applies to role trust policies for IAM roles used by EventBridge rules and EventBridge Pipes (principalevents.amazonaws.com/pipes.amazonaws.com,aws:SourceArn= the rule or pipe ARN) — not just the DLQ case called out above. See the IAM User Guide on The confused deputy problem.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。