Serverless Backend with AWS Lambda & API Gateway · درس

معالجة الأخطاء وإعادة المحاولة في آلات الحالات

اجعل سير العمل متينًا. تعلّم حقلي Retry وCatch في Step Functions، والتراجع الأسي، وكيفية توجيه حالات الفشل إلى حالات بديلة.

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

معالجة الأخطاء وإعادة المحاولة في آلات الحالات درس مجاني في Serverless Backend with AWS Lambda & API Gateway على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Serverless Backend with AWS Lambda & API Gateway، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Serverless Backend with AWS Lambda & API Gateway 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Failures Happen in Workflows

A Step Functions workflow chains many tasks. Any task can fail — a timeout, a throttle, or a thrown error. Built-in error handling lets the state machine recover instead of crashing.

Error Names

Step Functions classifies errors with names like States.Timeout, States.TaskFailed, and States.ALL. Your custom Lambda errors appear by their error name too.

The Retry Field

A Retry array on a Task state automatically re-runs it on matching errors.

"Retry": [{
  "ErrorEquals": ["States.TaskFailed"],
  "MaxAttempts": 3
}]

Exponential Backoff

Use IntervalSeconds and BackoffRate so each retry waits longer, easing pressure on a struggling downstream service.

"Retry": [{
  "ErrorEquals": ["States.ALL"],
  "IntervalSeconds": 2,
  "BackoffRate": 2.0,
  "MaxAttempts": 4
}]

The Catch Field

When retries are exhausted, a Catch block routes the workflow to a fallback state instead of failing the whole execution.

"Catch": [{
  "ErrorEquals": ["States.ALL"],
  "Next": "NotifyFailure"
}]

Capturing the Error

Use ResultPath in a Catch to pass the error details into the next state, so your fallback can log or react to what went wrong.

"Catch": [{
  "ErrorEquals": ["States.ALL"],
  "ResultPath": "$.error",
  "Next": "HandleError"
}]

Ordering Retry Rules

List more specific errors first. Step Functions evaluates Retry/Catch entries top to bottom, so a broad States.ALL should come last.

Timeouts as Safety Nets

Set TimeoutSeconds on a Task so a hung activity throws States.Timeout instead of running forever, which your Retry can then handle.

Fallback States

A fallback can be a Fail state that ends the execution with a clear cause, or a compensating action that undoes earlier work (the saga pattern).

Express vs Standard Error Behavior

Standard workflows keep full execution history for debugging failures; Express workflows are faster and cheaper but log to CloudWatch. Choose based on how you need to trace errors.

Designing Resilient Workflows

Combine the tools:

  • Retry transient errors with backoff
  • Catch terminal errors to a fallback
  • Set timeouts as safety nets
  • Capture error details with ResultPath

Quick Check

Test your Step Functions error-handling knowledge.

Recap

You learned resilient workflows:

  • Retry re-runs tasks on matching error names
  • IntervalSeconds and BackoffRate give exponential backoff
  • Catch routes exhausted errors to a fallback state
  • ResultPath captures the error; timeouts prevent hangs
البدء مجانًا

تعلم Serverless Backend with AWS Lambda & API Gateway مع معلم ذكاء اصطناعي — مجانًا

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

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

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

هل درس «معالجة الأخطاء وإعادة المحاولة في آلات الحالات» مجاني؟

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

ماذا ستتعلم في «معالجة الأخطاء وإعادة المحاولة في آلات الحالات»؟

اجعل سير العمل متينًا. تعلّم حقلي Retry وCatch في Step Functions، والتراجع الأسي، وكيفية توجيه حالات الفشل إلى حالات بديلة. تتمرن على Serverless Backend with AWS Lambda & API Gateway مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Serverless Backend with AWS Lambda & API Gateway؟

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

كم من الوقت يستغرق درس «معالجة الأخطاء وإعادة المحاولة في آلات الحالات»؟

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

هل يمكنني كتابة وتشغيل أكواد في درس Serverless Backend with AWS Lambda & API Gateway هذا؟

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

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

  1. مقدمة إلى AWS Step Functions
  2. بناء آلات الحالات
  3. تنسيق عمليات سير العمل المعقّدة
  4. معالجة الأخطاء وإعادة المحاولة في آلات الحالات
← العودة إلى Serverless Backend with AWS Lambda & API Gateway