Serverless Backend with AWS Lambda & API Gateway · บทเรียน

การจัดการข้อผิดพลาดและการลองใหม่ในเครื่องสถานะ

ทำให้เวิร์กโฟลว์ทนทาน เรียนรู้ฟิลด์ Retry และ Catch ของ Step Functions การหน่วงเวลาแบบทวีคูณ และวิธีกำหนดเส้นทางความล้มเหลวไปยังสถานะสำรอง

บทเรียน 4 จาก 413 ขั้นตอน

การจัดการข้อผิดพลาดและการลองใหม่ในเครื่องสถานะ เป็นบทเรียน Serverless Backend with AWS Lambda & API Gateway ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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 ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การจัดการข้อผิดพลาดและการลองใหม่ในเครื่องสถานะ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การจัดการข้อผิดพลาดและการลองใหม่ในเครื่องสถานะ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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 ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 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 ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. บทนำสู่ AWS Step Functions
  2. การสร้างเครื่องจักรสถานะ
  3. การประสานกระบวนการทำงานที่ซับซ้อน
  4. การจัดการข้อผิดพลาดและการลองใหม่ในเครื่องสถานะ
← กลับไปที่ Serverless Backend with AWS Lambda & API Gateway