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

تنسيق عمليات سير العمل المعقّدة

ابنِ عمليات سير عمل عديمة الخوادم متقدمة تتضمن منطقًا شرطيًا وتنفيذًا متوازيًا ومعالجة للأخطاء باستخدام Step Functions

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

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

Orchestrating Complex Workflows

Welcome! In this lesson, we'll dive into building sophisticated serverless workflows with AWS Step Functions.

We'll explore how to add decision-making, run tasks concurrently, and make your workflows resilient to errors.

Decision Making with Choice

The Choice state is your workflow's "if/else" statement. It allows your state machine to make decisions based on the input it receives.

  • Each choice rule has a condition (e.g., input value equals "X").
  • If a condition is met, the workflow transitions to a specified state.
  • A default state handles cases where no conditions match.

Choice State Example

Here's how a Choice state looks in your Step Functions definition. It checks an orderStatus field to decide the next step.

{  "StartAt": "CheckOrderStatus",  "States": {    "CheckOrderStatus": {      "Type": "Choice",      "Choices": [        {          "Variable": "$.orderStatus",          "StringEquals": "PENDING",          "Next": "ProcessPendingOrder"        },        {          "Variable": "$.orderStatus",          "StringEquals": "SHIPPED",          "Next": "NotifyShipping"        }      ],      "Default": "HandleUnknownStatus"    },    "ProcessPendingOrder": {      "Type": "Task",      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:processPending",      "End": true    },    "NotifyShipping": {      "Type": "Task",      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:notifyShipping",      "End": true    },    "HandleUnknownStatus": {      "Type": "Fail",      "Cause": "Unknown order status",      "Error": "InvalidOrderStatus"    }  }}

Running Tasks in Parallel

The Parallel state allows you to execute multiple branches of your workflow concurrently. This is great for tasks that don't depend on each other and can run at the same time.

  • Each branch runs independently.
  • The Parallel state waits for all branches to complete.
  • Outputs from all branches are combined into an array.

Parallel State Example

This Parallel state simultaneously processes an order and updates inventory, then combines their results.

{  "StartAt": "ProcessOrderAndInventory",  "States": {    "ProcessOrderAndInventory": {      "Type": "Parallel",      "Branches": [        {          "StartAt": "ProcessOrder",          "States": {            "ProcessOrder": {              "Type": "Task",              "Resource": "arn:aws:lambda:us-east-1:123456789012:function:processOrder",              "End": true            }          }        },        {          "StartAt": "UpdateInventory",          "States": {            "UpdateInventory": {              "Type": "Task",              "Resource": "arn:aws:lambda:us-east-1:123456789012:function:updateInventory",              "End": true            }          }        }      ],      "Next": "CombineResults"    },    "CombineResults": {      "Type": "Pass",      "End": true    }  }}

Handling Errors Gracefully

Things can go wrong! Step Functions provides robust error handling with the Catch field. You can specify what errors to catch and which state to transition to when an error occurs.

  • Errors are identified by their type (e.g., States.TaskFailed).
  • You can catch specific errors or a generic States.ALL.
  • The ResultPath specifies where the error output is placed.

Catch State Example

Here, if the ProcessPayment task fails, it's caught and the workflow moves to the RefundOrder state.

{  "StartAt": "ProcessPayment",  "States": {    "ProcessPayment": {      "Type": "Task",      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:processPayment",      "Catch": [        {          "ErrorEquals": [ "States.TaskFailed", "PaymentFailure" ],          "Next": "RefundOrder",          "ResultPath": "$.errorInfo"        }      ],      "Next": "CompleteOrder"    },    "RefundOrder": {      "Type": "Task",      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:refundOrder",      "End": true    },    "CompleteOrder": {      "Type": "Pass",      "End": true    }  }}

Retrying Failed Tasks

For transient errors (like network timeouts), it's often better to retry the task a few times before failing. The Retry field lets you define retry policies.

  • Specify which errors to retry.
  • Configure IntervalSeconds, MaxAttempts, and BackoffRate.
  • Exponential backoff (BackoffRate > 1) is highly recommended.

Retry State Example

This task will retry up to 3 times with exponential backoff if a Timeout or NetworkError occurs.

{  "StartAt": "CallExternalService",  "States": {    "CallExternalService": {      "Type": "Task",      "Resource": "arn:aws:lambda:us-east-1:123456789012:function:callExternalService",      "Retry": [        {          "ErrorEquals": [ "States.Timeout", "NetworkError" ],          "IntervalSeconds": 2,          "MaxAttempts": 3,          "BackoffRate": 1.5        }      ],      "End": true    }  }}

Orchestrating It All

The real power of Step Functions comes from combining these states. You can build highly sophisticated workflows by nesting Parallel states within Choices, adding Retries to Tasks, and Catching errors at various levels.

This allows you to model almost any business process, making your serverless applications robust and adaptable.

Workflow Logic Check

Consider a workflow that needs to:

  1. Check if a user is premium.
  2. If premium, send a personalized email AND update their loyalty points simultaneously.
  3. If not premium, send a standard email.
  4. Handle any email sending failures by logging them without stopping the workflow.

Which Step Functions states would be essential to implement this logic?

Recap: Complex Workflows

You've mastered advanced Step Functions concepts!

  • We used Choice states for conditional logic.
  • We leveraged Parallel states for concurrent execution.
  • We implemented robust error handling with Catch blocks.
  • And we learned about Retry policies for transient failures.

These tools allow you to build incredibly powerful and resilient event-driven serverless applications!

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

هل درس «تنسيق عمليات سير العمل المعقّدة» مجاني؟

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

ماذا ستتعلم في «تنسيق عمليات سير العمل المعقّدة»؟

ابنِ عمليات سير عمل عديمة الخوادم متقدمة تتضمن منطقًا شرطيًا وتنفيذًا متوازيًا ومعالجة للأخطاء باستخدام 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 منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 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