Serverless AWS Lambda Development · درس

نمط التوزيع المتشعب باستخدام SNS

تعلّم نمط المراسلة بالتوزيع المتشعب باستخدام Amazon SNS لتسليم حدث واحد إلى عدة مستهلكين مستقلين من Lambda بالتوازي.

الدرس 4 من 413 خطوة

نمط التوزيع المتشعب باستخدام SNS درس مجاني في Serverless AWS Lambda Development على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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.

البدء مجانًا

تعلم Serverless AWS Lambda Development مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «نمط التوزيع المتشعب باستخدام SNS» مجاني؟

نعم — نص درس «نمط التوزيع المتشعب باستخدام SNS» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Serverless AWS Lambda Development، انتقل إلى CoddyKit PRO. تتضمن دورة Serverless AWS Lambda Development 4 دروس في المجموع.

ماذا ستتعلم في «نمط التوزيع المتشعب باستخدام SNS»؟

تعلّم نمط المراسلة بالتوزيع المتشعب باستخدام Amazon SNS لتسليم حدث واحد إلى عدة مستهلكين مستقلين من Lambda بالتوازي. تتمرن على Serverless AWS Lambda Development مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Serverless AWS Lambda Development؟

لا تُشترط خبرة سابقة. Serverless AWS Lambda Development على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «نمط التوزيع المتشعب باستخدام SNS»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Serverless AWS Lambda Development هذا؟

نعم. كل درس في Serverless AWS Lambda Development يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. استدعاءات Lambda غير المتزامنة
  2. قوائم الانتظار للرسائل غير القابلة للتسليم (DLQ) لحالات الفشل
  3. تنسيق العمليات باستخدام AWS Step Functions
  4. نمط التوزيع المتشعب باستخدام SNS
← العودة إلى Serverless AWS Lambda Development