完整無伺服器應用

🔥 Vibe Prompt

「架構一個無伺服器 SaaS 應用:認證、API、資料庫、檔案上傳、非同步處理、監控。」

系統架構

CloudFront(SPA 託管)
    ↓
Cognito(認證:OAuth, MFA)
    ↓
API Gateway HTTP API
    ↓
Lambda(商業邏輯)
    ↓
DynamoDB + S3 + EventBridge
    ↓
Step Functions(工作流程)
    ↓
SES(郵件)+ SNS(推播)

基礎設施即程式碼

# 50 行搞定無伺服器架構
module "serverless" {
  source = "terraform-aws-modules/lambda/aws"
  
  functions = {
    api = {
      handler = "index.handler"
      runtime = "nodejs20.x"
      source_path = "./src/api"
      environment_variables = {
        TABLE_NAME = "orders"
        BUCKET_NAME = "uploads"
      }
    }
    worker = {
      handler = "index.handler"
      runtime = "python3.12"
      source_path = "./src/worker"
      timeout = 300
      memory_size = 1024
    }
  }
  
  api_gateway = {
    protocol = "HTTP"
    cors = { allow_origins = ["https://app.example.com"] }
  }
}

module "dynamodb" {
  source = "terraform-aws-modules/dynamodb-table/aws"
  tables = {
    orders = {
      hash_key = "PK"
      range_key = "SK"
      billing_mode = "PAY_PER_REQUEST"
    }
  }
}

監控與可觀測性

CloudWatch → 儀表板 + 警報 + 日誌
    ↓
X-Ray(分散式追蹤)
    ↓
EventBridge → PagerDuty(值班)

無伺服器課程完成!🎉

  • ✅ Lambda
  • ✅ API Gateway
  • ✅ DynamoDB & EventBridge
  • ✅ Step Functions
  • ✅ 完整 SaaS 應用

費用估算

| 服務 | 每月(1 萬使用者) | |------|-------------------| | Lambda | $2-5 | | API Gateway | $3 | | DynamoDB | $5-10 | | CloudFront | $1 | | Cognito | $0(免費用戶) | | 總計 | $10-20 |

解鎖完整教學內容

本章為付費內容。加入專案即可解鎖超過 5000 字的深度解析,包含 10 個以上神級 Prompt 與真實 Source Code 範例!