بناء آلات الحالات
صمّم ونفّذ أنواعًا مختلفة من آلات الحالات (Standard وExpress) لحالات استخدام متعددة، مع دمجها مع Lambda وخدمات أخرى
بناء آلات الحالات درس مجاني في Serverless Backend with AWS Lambda & API Gateway على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Serverless Backend with AWS Lambda & API Gateway، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Serverless Backend with AWS Lambda & API Gateway 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Build Your First Workflow
Welcome back! In the previous lesson, we learned what AWS Step Functions are. Now, let's dive into building them!
You'll learn how to define different steps (states) and connect them to create powerful, automated workflows. We'll also explore the two main types of workflows: Standard and Express.
Anatomy of a State Machine
A Step Functions state machine is a workflow that defines a series of steps, called states. Each state performs a specific task or makes a decision.
- States: The individual steps in your workflow.
- Transitions: Rules that determine which state comes next.
- Input/Output: Data passed between states.
Think of it like a flowchart, but executed by AWS!
Common State Types
Step Functions offers various state types to build your logic:
- Task: Performs work by calling a service (e.g., Lambda, ECS).
- Pass: Passes its input to its output without performing work. Useful for debugging or structuring.
- Choice: Adds branching logic (if/else).
- Wait: Pauses the execution for a specified time or until a specific time.
- Succeed/Fail: Stops the execution successfully or with an error.
- Parallel: Executes multiple branches in parallel.
Defining a Simple Pass State
Let's start with a simple Pass state. This state simply takes its input and passes it as output. It's often used for testing or structuring your state machine.
State machines are defined using Amazon States Language (ASL), which is a JSON-based structure.
Pass State ASL Example
Here's how a Pass state looks in ASL. It defines the state name, its type, and where to go next.
{ "Comment": "A simple Pass state machine",
"StartAt": "HelloWorld",
"States": {
"HelloWorld": {
"Type": "Pass",
"Result": {
"message": "Hello from Step Functions!"
},
"End": true
}
}
}Standard Workflows: The Durable Choice
AWS Step Functions offers two workflow types: Standard and Express.
Standard Workflows are ideal for long-running, durable, and auditable workflows. They can run for up to a year!
- Durability: Retains full execution history for up to 90 days.
- Auditability: Easy to track every step and input/output.
- Use Cases: Order fulfillment, data processing pipelines, human approvals.
Express Workflows: Speed and Scale
Express Workflows are designed for high-volume, event-driven workloads. They are much faster and more cost-effective for short-duration tasks.
- Speed: Can complete thousands of executions per second.
- Cost: Priced per execution and duration, often cheaper for short tasks.
- History: Execution history is limited (up to 90 days in CloudWatch Logs, not directly in Step Functions console).
- Use Cases: Microservice orchestration, real-time streaming data processing, mobile backend processing.
Integrating Lambda: The Task State
One of the most common ways to perform work in a state machine is using a Task state to invoke an AWS Lambda function.
The Resource field in the ASL specifies the ARN of the Lambda function to call.
Example Lambda for Step Functions
This simple Python Lambda function receives an event (input from Step Functions) and returns a modified message. Step Functions will pass its output to the next state.
import json
def lambda_handler(event, context):
print(f"Received event: {json.dumps(event)}")
name = event.get('name', 'World')
return {
'statusCode': 200,
'body': f"Hello, {name}! This is from Lambda."
}Workflow Type Challenge
You need to build a workflow for processing thousands of incoming IoT sensor readings every minute. Each reading takes less than 1 second to process.
Recap: Building Workflows
Great job! You've learned the fundamentals of building AWS Step Functions state machines:
- State machines are defined by a series of states and transitions.
- Key state types include Task, Pass, Choice, and Wait.
- Standard Workflows are for long-running, auditable processes.
- Express Workflows are for high-volume, short-duration tasks.
- You can integrate Lambda functions using a
Taskstate.
Next, we'll explore orchestrating complex workflows!
الأسئلة الشائعة
هل درس «بناء آلات الحالات» مجاني؟
نعم — نص درس «بناء آلات الحالات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Serverless Backend with AWS Lambda & API Gateway، انتقل إلى CoddyKit PRO. تتضمن دورة Serverless Backend with AWS Lambda & API Gateway 4 دروس في المجموع.
ماذا ستتعلم في «بناء آلات الحالات»؟
صمّم ونفّذ أنواعًا مختلفة من آلات الحالات (Standard وExpress) لحالات استخدام متعددة، مع دمجها مع Lambda وخدمات أخرى تتمرن على Serverless Backend with AWS Lambda & API Gateway مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Serverless Backend with AWS Lambda & API Gateway؟
لا تُشترط خبرة سابقة. Serverless Backend with AWS Lambda & API Gateway على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «بناء آلات الحالات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Serverless Backend with AWS Lambda & API Gateway هذا؟
نعم. كل درس في Serverless Backend with AWS Lambda & API Gateway يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- مقدمة إلى AWS Step Functions
- بناء آلات الحالات
- تنسيق عمليات سير العمل المعقّدة
- معالجة الأخطاء وإعادة المحاولة في آلات الحالات