학습 목표
Serverless가 서버 관리 위임·사용량 과금·이벤트 구동을 핵심으로 함을 설명할 수 있다.
FaaS·event-driven 패턴으로 요청·비동기 워크로드를 설계할 수 있다.
cold start·concurrency가 latency·비용에 미치는 영향을 설명할 수 있다.
serverless vs container를 트래픽·팀·운영 축에서 비교할 수 있다.
Part 2 CDK로 serverless 스택을 코드화할 준비를 할 수 있다.
문제 상황
- 트래픽 10배 차이 — EC2 24/7 과금, 야간 idle 80%
- “서버리스로 가자” — VPC Lambda ENI·cold start 3초 — API SLA 깨짐
- SQS 100만 메시지 — Lambda 동시성 한도·throttle — 설계 미스
- K8s Deployment에 익숙 — Lambda 상태·파일시스템·연결 풀 제약 모름
- Platform Lambda 개요는 봤지만 — 아키텍처 선택 기준이 없음
- Part 2 CDK로 VPC·Lambda 예제는 봤지만 — 언제 serverless인지 모름
- 이벤트 기반이 좋다는 말만 — 동기 API vs 비동기 경계 불명
Part 2 CDK를 마쳤다. Part 3 Serverless — FaaS·이벤트·cold start와 컨테이너 대비 선택 축이다. Lambda·API Gateway hands-on은 11편, SAM은 12편.
1. Serverless란?
Serverless — 개발자가 서버·OS·패치·용량을 직접 관리하지 않고, 클라우드가 실행·스케일을 담당하는 모델.

| 계층 | 예 (AWS) | 특징 |
|---|---|---|
| Compute | Lambda | 요청·이벤트 단위 실행 |
| API | API Gateway | HTTP 라우팅·인증 |
| Data | DynamoDB, S3 | 관리형·API 접근 |
| Messaging | SQS, EventBridge | 비동기·decouple |
| 과금 | invocation·duration·storage | idle 비용 없음 (compute) |
Client ──► API Gateway ──► Lambda ──► DynamoDB
│
└──► SQS ──► Lambda worker (async)
- FaaS (Function as a Service) — 함수 단위 compute (Lambda)
- BaaS — auth·DB·storage 서비스 (Cognito, DynamoDB)
- ≠ "서버 없음" — 서버는 있으나 보이지 않음
- IaC — CDK·SAM·TF
aws_lambda_function(11~12편)
2. Event-driven 아키텍처
Serverless는 이벤트에 반응해 느슨하게 연결된다.

| 패턴 | 흐름 | 예 |
|---|---|---|
| Sync | 요청 → 응답 한 번에 | REST API → Lambda |
| Async | 이벤트 적재 → 나중 처리 | S3 upload → Lambda |
| Fan-out | 한 이벤트 → 여러 consumer | EventBridge → 3 targets |
| Queue buffer | burst 흡수 | API → SQS → Lambda |
- Decouple — producer·consumer 독립 배포·스케일
- At-least-once — SQS·Lambda 재시도 — 멱등 handler (13편)
- Ordering — FIFO queue·partition key 필요 시 명시
- Architecture EDA — 본 편은 serverless 구현 관점
3. Cold start · Concurrency
Lambda는 요청마다(또는 warm 인스턴스) 실행 — cold start가 latency에 직결.

| 단계 | 내용 |
|---|---|
| Init | runtime·코드 로드 |
| Extension | (선택) layer·agent |
| Handler | 비즈니스 로직 |
| Warm | 이후 요청 재사용 (일정 시간) |
| 요인 | 영향 |
|---|---|
| Runtime | Java·.NET > Node·Python (대략) |
| Package size | zip 클수록 init 느림 |
| VPC | ENI attach — cold 증가 (7편) |
| Memory | CPU 비례 — 메모리 up → init 단축 경우 |
| Provisioned concurrency | warm 유지 — 비용 ↑ latency ↓ |
- Latency-sensitive sync API — cold start 측정 필수
- Reserved / provisioned — 피크 SLO용
- Account concurrency — 기본 한도 — burst throttle
- Container — 프로세스 상시 — cold 없음 (대신 idle 비용)
4. Serverless vs Container
같은 HTTP API라도 운영 모델이 다르다.

| Serverless (Lambda) | Container (ECS/EKS) | |
|---|---|---|
| 단위 | 함수 | 이미지·pod |
| 스케일 | 자동 (concurrency) | HPA·replica |
| idle 비용 | 없음 (compute) | 상시 과금 |
| 실행 시간 | 최대 15분 (Lambda) | 제한 없음 |
| 상태 | ephemeral /tmp | 디스크·메모리 유지 |
| 네트워킹 | VPC 선택 시 복잡 | 일반적 |
| 배포 | zip·image 버전 | rolling·canary |
| IaC | SAM·CDK·TF | K8s manifest·CDK |
- Spiky·불규칙 트래픽 — serverless 유리
- 장시간·heavy CPU·WebSocket 장기 — container 검토
- 하이브리드 — API Lambda, batch Fargate (흔함)
- Platform K8s — 운영 깊이; 본 시리즈는 IaC·선택
5. 선택 가이드

| 시나리오 | 쪽 | 이유 |
|---|---|---|
| API 간헐·MVP | Serverless | idle 0·빠른 배포 |
| p99 < 100ms sync | Container 또는 provisioned | cold 리스크 |
| 파일 처리 S3 trigger | Serverless | 이벤트 네이티브 |
| 15분+ job | Container·Step Functions | Lambda 한도 |
| 기존 K8s·service mesh | Container | sunk cost |
| 이벤트 파이프라인 fan-out | Serverless + queue | scale per event |
# code/serverless-fit.yaml (발췌)
workloads:
- name: webhook-ingest
pattern: async
fit: serverless
reason: "spiky · short handler"
- name: report-generator
pattern: batch-30min
fit: container
reason: "exceeds lambda timeout"
- name: public-api-p99-50ms
pattern: sync
fit: container-or-provisioned
reason: "cold start budget"
- 작은 팀 — serverless로 운영 최소화
- 규제·네트워크 — VPC Lambda·private API 설계 (11편)
- vendor lock-in — 이벤트 스키마·포터블 runtime 고려
6. IaC 관점
Serverless도 코드로 — 콘솔 클릭만으로는 재현·리뷰 불가.
| 도구 | 역할 |
|---|---|
| CDK | lambda.Function, apigateway.RestApi (7편) |
| SAM | AWS::Serverless::Function — Lambda 특화 (12편) |
| Terraform | aws_lambda_function — 멀티 클라우드 |
| Serverless Framework | plugin·multi-cloud (12편) |
- Asset — handler zip·Docker image —
cdk deploybootstrap (9편) - 환경 — dev/staging/prod stack·alias (5편 패턴)
- 테스트 — template assertion + local invoke (12편)
7. 실무 체크리스트
| # | 질문 |
|---|---|
| 1 | 워크로드가 15분·메모리 한도 안인가 |
| 2 | cold start가 SLA를 만족하는가 |
| 3 | handler가 멱등한가 (재시도·중복) |
| 4 | concurrency 한도·reserved가 설계됐는가 |
| 5 | VPC가 필요한가 — ENI·cold tradeoff |
| 6 | container가 더 나은 경우를 검토했는가 |
정리
- Serverless — 관리 위임·이벤트 구동·사용량 과금
- Event-driven — sync API vs async queue·fan-out
- Cold start·concurrency — latency·비용 핵심 변수
- Container — 장시간·상태·K8s·예측 트래픽에 유리
- 선택 — 트래픽 형태·SLO·팀·기존 스택
- 11편 — Lambda·API Gateway 구체
다음에 다룰 것
- Lambda와 API Gateway
- handler, runtime, IAM role, REST·HTTP API 통합
해당 내용은 AWS Lambda Developer Guide, AWS Well-Architected Serverless Lens 를 기반으로 합니다.
'Infrastructure as Code' 카테고리의 다른 글
| Lambda와 API Gateway (0) | 2026.07.16 |
|---|---|
| CDK 테스트와 배포 (0) | 2026.07.10 |
| CDK vs Terraform (0) | 2026.07.10 |
| CDK로 인프라 정의 (0) | 2026.07.09 |
| AWS CDK 개요 (0) | 2026.07.07 |