Lộ trình
Amazon Web ServicesAssociateTuần 2: Đào sâu dịch vụ cốt lõiBài 13 / 30

Ngày 13: Serverless cơ bản

Thời lượng: 45 phút
Mục tiêu: 2 nhiệm vụ chính
Tiến độ lộ trình
aws-saa-c03ngày 13
hoàn thành13 / 30 bài
Bối cảnh bài học

Chọn Lambda, API Gateway và event-driven services theo execution model, timeout, retry, idempotency và observability.

đọc hiểuthực hànhcheckpoint
Bài giảng hôm nay

Học hiểu, rồi mới thực hành

Chọn Lambda, API Gateway và event-driven services theo execution model, timeout, retry, idempotency và observability.

Bắt đầu đọc bài giảng

Nhiệm vụ bài học hôm nay

  • Tìm hiểu Lambda, API Gateway, Step Functions
  • Thực hành viết 1 Lambda function đơn giản
Instructor walkthrough

Bài giảng chi tiết: từ bài toán đến bằng chứng

Scenario xuyên suốt

Một API cần scale theo request, một job xử lý file có thể retry và một workflow cần nhiều bước. Dùng Lambda cho mọi thứ mà không xét timeout, concurrency và duplicate event sẽ tạo lỗi khó debug.

01Đọc bài toán

Xác định actor, workload, constraint và trạng thái cuối cần đạt.

02Vẽ luồng / boundary

Chỉ ra request, dependency, identity và failure domain trước khi chọn công cụ.

03Chọn và thực hành

Thay đổi nhỏ nhất trong lab cô lập; command nào cũng phải nói rõ nó kiểm tra điều gì.

04Kiểm chứng / recovery

Đối chiếu trạng thái thực tế, tạo một failure variant và ghi cách hoàn tác.

Cách nối lý thuyết với thực tế
  • Lambda là function execution theo event, có timeout/memory/concurrency và execution role.
  • API Gateway là API front door; event source có retry/DLQ semantics khác nhau.
  • Idempotency, observability, cold start, package/dependency và cost là phần design.
  • Step Functions điều phối workflow; SQS/EventBridge/SNS giải quyết messaging/eventing khác nhau.

Event-driven architecture

Chọn pattern trước: request/response, event processing hay workflow orchestration. Lambda cần timeout, memory, concurrency, execution role, retry và idempotency. API Gateway chỉ là front door; messaging/event services có semantics khác nhau.

Bài tập

Thiết kế ba flow: API synchronous, S3 upload asynchronous và payment workflow. Ghi duplicate event, retry/DLQ, timeout, state và observability. Một flow đạt chuẩn phải mô tả cả khi downstream lỗi.

Bài giảng chuyên sâu

Serverless cần semantics của event và retry

API synchronous cần timeout và response contract; S3 upload có thể kích hoạt Lambda asynchronous; payment workflow cần state/orchestration. Lambda có timeout, memory, concurrency, execution role và retry behavior; API Gateway chỉ là front door. SQS, SNS, EventBridge và Step Functions giải quyết queue, fan-out/event routing và workflow khác nhau.

Retry có thể tạo duplicate side effect. Handler phải idempotent bằng event id/order id hoặc conditional write; lỗi không retry được cần DLQ. Concurrency và downstream limit phải được ghép vào thiết kế, nếu không scale tự động sẽ biến thành overload.

Bài tập: vẽ ba flow sync/async/workflow, đánh dấu timeout, retry, idempotency key, DLQ, IAM role và metric. Failure drill: duplicate event, downstream timeout và poison message.

Terminal reference

Command list và cách dùng

Chạy từng lệnh theo đúng thứ tự. Trước các lệnh có thể tạo hoặc thay đổi tài nguyên, hãy kiểm tra profile, account và region.

Commands · read-only checkpoints
aws lambda list-functions --profile study --output table
aws apigateway get-rest-apis --profile study --output table
Hands-on lab

Thực hành theo scenario

Vẽ API synchronous, file event asynchronous và multi-step workflow. Với mỗi flow ghi timeout, retry, idempotency key, DLQ/error path, IAM role và log/metric. Dùng Lambda invoke read-only hoặc pseudocode; không commit secret.

Evidence checkpoint

Kiểm chứng kết quả

Không coi lệnh chạy thành công là đủ. Hãy đối chiếu output với trạng thái mong đợi:

  • Chọn đúng sync/async/workflow pattern.
  • Nêu retry/duplicate và idempotency behavior.
  • Phân biệt API Gateway, SQS, SNS, EventBridge và Step Functions theo vai trò.
  • Có error path, DLQ hoặc retry policy phù hợp.
Transfer to exam / production

Bẫy thường gặp và trade-off

Serverless không có nghĩa không cần architecture: timeout, concurrency, permissions, retries, observability và cost vẫn phải thiết kế.

Checkpoint · 3 phút

Kiểm tra nhanh

Câu hỏi: Consumer xử lý event có thể nhận cùng một message nhiều lần. Control nào cần thiết nhất?

Kết thúc bài

Checklist trước khi sang Ngày 2