0Pricing
AWS for Backend Developers (EC2, S3, RDS, Lambda) · บทเรียน

การตรวจสอบและแก้ไขข้อบกพร่องของฟังก์ชัน Lambda

เรียนรู้การสังเกตการณ์ บันทึก ติดตาม และแก้ไขปัญหาฟังก์ชัน AWS Lambda ในระบบจริงด้วย CloudWatch, X-Ray และการบันทึกแบบมีโครงสร้าง

การตรวจสอบและแก้ไขข้อบกพร่องของฟังก์ชัน Lambda เป็นบทเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AWS for Backend Developers (EC2, S3, RDS, Lambda) มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Why Observability Matters

Serverless functions are short-lived and invisible — you cannot SSH into them. Observability is how you understand what your Lambda is doing.

The three pillars are logs, metrics, and traces.

Logging with CloudWatch

Anything your function writes to stdout/stderr goes to CloudWatch Logs automatically. Each function gets its own log group.

exports.handler = async (event) => {
  console.log('Received event:', JSON.stringify(event));
  return { statusCode: 200, body: 'OK' };
};

Structured Logging

Plain text logs are hard to query. Log JSON objects so you can filter on fields later.

  • Include a requestId
  • Include severity and context
console.log(JSON.stringify({
  level: 'INFO',
  requestId: context.awsRequestId,
  message: 'Order processed',
  orderId: 42
}));

Built-in Lambda Metrics

Lambda publishes metrics to CloudWatch out of the box:

  • Invocations — how often it ran
  • Errors — failed executions
  • Duration — execution time
  • Throttles — rejected due to concurrency limits

Setting Alarms on Errors

Create a CloudWatch alarm so you get notified when error rates spike, instead of finding out from angry users.

aws cloudwatch put-metric-alarm \
  --alarm-name lambda-errors \
  --metric-name Errors \
  --namespace AWS/Lambda \
  --threshold 1 \
  --comparison-operator GreaterThanThreshold \
  --evaluation-periods 1

Distributed Tracing with X-Ray

AWS X-Ray traces a request as it flows through Lambda, DynamoDB, S3, and other services. It reveals where time is spent and which downstream call is slow.

Enable Active tracing in the function configuration.

Cold Starts

A cold start happens when Lambda spins up a fresh execution environment. It adds latency to the first request.

Watch Init Duration in your logs to measure cold start impact.

Reducing Cold Starts

Ways to reduce cold start pain:

  • Use Provisioned Concurrency to keep environments warm
  • Keep deployment packages small
  • Avoid heavy initialization at module load

Handling Errors Gracefully

Wrap risky code in try/catch and return meaningful errors. Unhandled exceptions count as Lambda errors and may trigger retries.

exports.handler = async (event) => {
  try {
    return await process(event);
  } catch (err) {
    console.error('Processing failed', err);
    throw err;
  }
};

Dead Letter Queues

For asynchronous invocations that keep failing, configure a Dead Letter Queue (DLQ) using SQS or SNS. Failed events land there so you can inspect and reprocess them.

Putting It Together

A well-monitored Lambda has:

  • Structured JSON logs
  • CloudWatch alarms on Errors and Duration
  • X-Ray tracing enabled
  • A DLQ for failed async events

Quick Check

Test your debugging knowledge.

Recap

You learned to monitor and debug Lambda:

  • CloudWatch Logs capture stdout/stderr
  • Metrics and alarms alert on errors
  • X-Ray traces distributed calls
  • DLQs capture failed async events

Good observability turns invisible serverless failures into solvable problems.

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

บทเรียน “การตรวจสอบและแก้ไขข้อบกพร่องของฟังก์ชัน Lambda” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การตรวจสอบและแก้ไขข้อบกพร่องของฟังก์ชัน Lambda” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AWS for Backend Developers (EC2, S3, RDS, Lambda) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AWS for Backend Developers (EC2, S3, RDS, Lambda) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การตรวจสอบและแก้ไขข้อบกพร่องของฟังก์ชัน Lambda”

เรียนรู้การสังเกตการณ์ บันทึก ติดตาม และแก้ไขปัญหาฟังก์ชัน AWS Lambda ในระบบจริงด้วย CloudWatch, X-Ray และการบันทึกแบบมีโครงสร้าง คุณปฏิบัติ AWS for Backend Developers (EC2, S3, RDS, Lambda) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน AWS for Backend Developers (EC2, S3, RDS, Lambda) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การตรวจสอบและแก้ไขข้อบกพร่องของฟังก์ชัน Lambda” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) นี้ได้ไหม

ได้ บทเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

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

  1. AWS Lambda คืออะไร
  2. สร้างฟังก์ชัน Lambda แรกของคุณ
  3. ทริกเกอร์และการผสานรวมของ Lambda
  4. การตรวจสอบและแก้ไขข้อบกพร่องของฟังก์ชัน Lambda
← กลับไปที่ AWS for Backend Developers (EC2, S3, RDS, Lambda)