What Is Serverless
Upload your code and the cloud automatically provides the execution environment. When there are no requests, the cost is zero. Servers still exist—developers just don't manage them.
Practical Lambda Example: Auto-Generating Image Thumbnails
import boto3
from PIL import Image
import io
def handler(event, context):
s3 = boto3.client('s3')
bucket = event['Records'][0]['s3']['bucket']['name']
key = event['Records'][0]['s3']['object']['key']
# 원본 이미지 다운로드
response = s3.get_object(Bucket=bucket, Key=key)
image = Image.open(io.BytesIO(response['Body'].read()))
# 썸네일 생성 (200x200)
image.thumbnail((200, 200), Image.LANCZOS)
buffer = io.BytesIO()
image.save(buffer, format='JPEG', quality=85)
buffer.seek(0)
s3.put_object(
Bucket=bucket,
Key=f"thumbnails/{key}",
Body=buffer.getvalue(),
ContentType='image/jpeg'
)
return {'statusCode': 200}Lambda Deployment Configuration
# serverless.yml
provider:
name: aws
runtime: python3.12
architecture: arm64 # Graviton: 20% 저렴
memorySize: 512
timeout: 30
functions:
thumbnail:
handler: handler.handler
events:
- s3:
bucket: my-bucket
event: s3:ObjectCreated:*
rules:
- prefix: uploads/
- suffix: .jpgCold Start Optimization
Cold Start 시간:
- Python 3.12: ~300ms
- Node.js 20: ~200ms
- Go 1.21: ~50ms# 전역 초기화 (컨테이너 재사용)
s3 = boto3.client('s3') # 1회만 초기화
def handler(event, context):
response = s3.get_object(...) # 재사용# Provisioned Concurrency로 Cold Start 제거
functions:
api:
provisionedConcurrency: 5 # 5개 인스턴스 항상 웜Assessing Serverless Fit
Suitable workloads:
- Event-driven processing (file uploads, message queues)
- Irregular traffic (APIs with peaks)
- Batch/scheduled jobs (cron)
Unsuitable workloads:
- Long-running work over 15 minutes
- Extremely low latency (<10ms)
- GPU-intensive compute
Cost Comparison
| Approach | Cost for 1M requests/month |
|---|---|
| Lambda | ~$10 |
| ECS Fargate (always-on) | ~$45 |
| EC2 t3.micro (always-on) | ~$9 (fixed) |
When traffic is irregular, Lambda is dramatically cheaper. Under 24/7 high load, EC2/ECS is more cost-effective.
Serverless aims for "infrastructure management time = 0." Start small and expand gradually.
Nodelog는 모든 콘텐츠의 내용과 출처를 공개 전에 검토합니다. 환경(OS·버전)에 따라 결과가 달라질 수 있는 기술 정보는 공식 문서와 함께 확인하며, 검토 기준과 정정 원칙은 편집 정책에서 안내합니다. 오류를 발견하시면 이메일로 제보해 주세요 — 확인 후 신속히 정정합니다.
Comments
Be the first to comment.