0Pricing
Serverless AWS Lambda Development · レッスン

SNSによるファンアウトパターン

Amazon SNSを使ったファンアウトメッセージングパターンで、1つのイベントを複数の独立したLambdaコンシューマーに並列配信する方法を学びます。

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

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

What is Fan-Out?

Fan-out means a single event is delivered to many subscribers at once, each processing it independently and in parallel.

Why Not Call Each Directly?

Calling each downstream function from your producer tightly couples them. Adding a consumer means changing the producer. Fan-out decouples this.

SNS as the Hub

Amazon SNS is a pub/sub topic. Publishers send a message once; SNS delivers a copy to every subscriber, including multiple Lambdas.

Publishing a Message

The producer publishes to the topic ARN. It does not know or care who is subscribed.

import boto3, json
sns = boto3.client('sns')
sns.publish(
  TopicArn='arn:aws:sns:us-east-1:123:orders',
  Message=json.dumps({'orderId': 42})
)

The SNS Event Shape

Each subscribed Lambda receives the message wrapped in an SNS records envelope.

{
  "Records": [{
    "Sns": {
      "Message": "{\"orderId\": 42}",
      "TopicArn": "arn:aws:sns:us-east-1:123:orders"
    }
  }]
}

A Consumer Handler

Each consumer parses the message from the record and does its own job: one emails a receipt, another updates inventory.

import json

def handler(event, context):
    for record in event['Records']:
        msg = json.loads(record['Sns']['Message'])
        print('Processing order', msg['orderId'])

Fan-Out plus SQS

For reliability, subscribe SQS queues to the topic and let Lambda poll the queues. This buffers spikes and gives each consumer its own retry and DLQ.

Message Filtering

SNS filter policies let a subscriber receive only messages matching attributes, so not every consumer processes every event.

{
  "eventType": ["order.created"]
}

SNS vs EventBridge

SNS is simple, high-throughput pub/sub. EventBridge adds richer routing, schemas, and many SaaS sources. Choose SNS for raw fan-out, EventBridge for complex routing.

Ordering Caveat

Standard SNS topics do not guarantee order or exactly-once delivery. Use SNS FIFO topics when ordering and deduplication matter.

Idempotent Consumers

Because a message may be delivered more than once, each consumer should be idempotent so duplicates do not cause double effects.

Quick Check

Test your fan-out knowledge.

Recap

You learned the fan-out pattern: publish once to SNS, deliver to many parallel consumers, add SQS for durability, filter messages, and keep consumers idempotent.

よくある質問

「SNSによるファンアウトパターン」レッスンは無料ですか?

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

「SNSによるファンアウトパターン」で何を学びますか?

Amazon SNSを使ったファンアウトメッセージングパターンで、1つのイベントを複数の独立したLambdaコンシューマーに並列配信する方法を学びます。 ブラウザで直接実行するハンズオンコードでServerless AWS Lambda Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「SNSによるファンアウトパターン」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. Lambdaの非同期呼び出し
  2. 失敗時のデッドレターキュー(DLQ)
  3. AWS Step Functionsによるオーケストレーション
  4. SNSによるファンアウトパターン
← Serverless AWS Lambda Developmentに戻る