Lesson 118 — Advanced

Deployment on AWS

CI ne image bana di, ab usse cloud pe chalana hai — bina keys ko machines pe bikhraaye, aur bina streaming ko load balancer kaat de. Is lesson mein hum EC2 + IAM role, Secrets Manager, CodeDeploy releases, blue/green ka choice, ALB timeouts, aur CPU ki jagah concurrency par scaling dekhenge.

⏱ 30 min• Advanced• CI/CD with GitHub Actions

AWS pe deploy — structure

Kya hai?

AWS deployment matlab tumhari container stack ko EC2 instances pe chalana, images ko registry se pull karna, secrets ko Secrets Manager se dena, aur release ko CodeDeploy se replace karna — sab health checks ke saath.

Kab kaam aata hai?

Jab staging pass ho gaya aur users ko chahiye — ya compliance kehti hai ki workload specific cloud pe. Deploy ka structure kisi bhi cloud pe same soch hota hai.

Kahan milta hai?

EC2 (compute), IAM (identity), Secrets Manager (keys), CodeDeploy (releases), ALB (traffic), Auto Scaling (capacity) — ye components milke stack chalate hain.

Pehla principle: machine ko kuch yaad nahi, key uske paas kuch nahi. Har instance apni zaroorat ka access role se leta hai, secrets startup pe Secret Manager se aate hain. Iska fayda — rotation aur revocation bina kisi machine ko chhuye mumkin hai.

Map karke chalo: Jo tumne compose stack mein banaya tha (backend, frontend, vector DB), uska deployment plan hi AWS mapping hai: service → instance/service, volume → EBS, healthcheck → target group. Naya architecture nahi, wahi stack bas orked.

EC2, IAM role aur Secrets Manager

instance startup (user data, conceptual):
  apt-get install docker
  aws ecr get-login | docker login     # IAM role se, key file nahi
  docker pull registry/app:${TAG}
  docker run -d --restart unless-stopped \
    -e PROVIDER_API_KEY="$(aws secretsmanager \
       get-secret-value --secret-id prod/llm/key --query SecretString)" \
    registry/app:${TAG}

# na ~/.aws/credentials file, na hardcoded key — role hi identity hai
Security minimum: Instance pe koi long-lived access key nahi. Role-based access ka fayda: key leak ka scene hi khatam, aur audit mein dikhta hai ki kaunsi instance ne kab kis secret ko padha.

CodeDeploy — in-place vs blue/green

IN-PLACE:
old instance -> naya image pull -> restart -> health check
  + kharcha kam (same instances)
  - restart ke dauran gap, rollback = purana image wapas (slow)

BLUE/GREEN:
blue (old) live
green (new) stack boot -> health check -> shift traffic -> blue retire
  + zero-downtime, rollback = traffic wapas blue (seconds)
  - do stack ka kharcha chhoti der ke liye

LLM app default: blue/green — streaming app pe restart gap dikhta hai
Choice rule: Budget tight aur downtime chalega → in-place. User-facing streaming app → blue/green. Beech ka koi jugaad mat banao — do tareeke, clear trade-off, decide karke likh lo.

Load balancer aur streaming timeouts

user -> ALB (HTTPS) -> target group (instances) :8000

ALB settings jo LLM apps ke liye matter karte hain:
  idle timeout        : stream ke beech gap se zyada (default se upar)
  target group health : /readyz (healthz nahi)
  deregistration      : drain — purane requests poori hone do

# galati: idle timeout chhota -> 30s+ ke stream beech mein kat jaate hain
# aur: websocket/SSE ke liye ALB buffering off / compatible settings
LLM-specific: Normal web app ke defaults yahan kaafi nahi — streams lambi hain aur thinking gaps bhi. ALB ka idle timeout tumhare sabse lambi stream se zyada hona chahiye, warna user ko dikhega ki jawab kat gaya.

Auto Scaling — CPU nahi, concurrency par

LLM app ka CPU profile:
  request aayi -> 2s compute -> 25s PROVIDER ka intezaar -> reply
  CPU utilization: aksar 5-15%  ->  CPU scaling: "sab shaant hai"

sahi signal: in-flight requests per instance (concurrency)
  concurrency target: e.g. N requests per instance
  -> N se zyada -> instance add
  -> derat ko traffic low -> remove

# aur: provider ke rate limits bhi ek cap hain — scaling se pehle unhe dekho
Test karke dekho: Load test chalao aur dekho kab scale out hota hai — aur us waqt bottleneck kya tha: instances ya provider rate limit. Ye do alag cheezein hain, aur galat pehchaan pe galat kharcha hota hai.

Exercise

Question: Instance access dene ka safe tareeka — IAM role ya usme access key rakhna?

Question: Provider keys ko AWS mein store karne wala service kya kehlata hai?

Question: Zero-downtime release jisme do parallel stacks hote hain — uska naam? (in-place / blue green)

Question: LLM app ko scale kis signal par karna chahiye — CPU ya concurrency?

Common mistakes

Desi example: Delivery hub ka fleet

Hub pe gaadi (instances) us waqt busy nahi jab load zyada hai — par kitne order pending hain wo kabhi dikhta hai (concurrency). Manager CPU nahi, pending board dekhta hai — aur nayi gaadi tab bhejta hai jab limit ek insaan se zyada ho:

text
gaadi     -> instance (role se access, key nahi)
order slip-> secret manager se utha (startup)
new route-> blue/green (nayi gaadi, purani ready)
board     -> in-flight count (scaling signal)
phone limit-> provider rate limit (pehle wala cap)
Interview angle — yahan se sawaal aate hain
  • Q: IAM role aur access key mein farq? — Role temporary credentials deta hai bina file ke; access key static hai, leak risk, rotation mushkil.
  • Q: Blue/green kyun prefer karte hain LLM apps mein? — Zero-downtime, seconds mein rollback; streaming restart gap se bachti hai.
  • Q: LLM app CPU scaling pe kyun nahi? — Waqt model provider ke intezaar mein jaata hai; sahi proxy hai in-flight concurrency.
  • Q: Streaming deploy ke waqt kya dekhna hai? — ALB idle timeout, deregistration drain, aur readiness-based target health.
Lesson complete?

Cloud pe health-checked, scalable stack chal raha hai. Agla lesson — Monitoring & Observability — mein live system ke signals: metrics, traces, alerts aur online evals jodenge.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course