Lesson 06 � Intermediate

CLOUD PAR
DEPLOY KARO.

AI applications ko internet pe deploy karna seekho � AWS, GCP, Azure jaise platforms se serverless aur container-based deployment.

? 22 min✓ Intermediate✓ Prerequisite: Docker

Cloud Deployment kya hai?

Cloud deployment ka matlab hai apne AI applications ko internet pe deploy karna taaki duniya bhar ke log use kar sakein. Aapko apna server khareedne ki zaroorat nahi � AWS, GCP, Azure jaise providers sab kuch manage karte hain.

WHAT

Cloud deployment mein aapka application internet pe running hota hai, kisi bhi device se access kar sakte ho. Servers, storage, networking sab provider handle karta hai.

WHEN

Jab aapko apne AI models ya applications ko production mein deploy karna ho, ya scaling ki zaroorat ho.

WHERE

Startups se lekar enterprise companies tak, sab cloud use karte hain for deployment.

Major Cloud Platforms

AWS

Duniya ka sabse bada cloud platform. Lambda, EC2, S3, SageMaker jaise services. AI/ML ke liye bahut powerful tools available hain.

GCP

Google ka cloud platform. Cloud Run, Vertex AI, BigQuery. TensorFlow aur ML services ke liye best choice.

AZURE

Microsoft ka cloud platform. Azure Functions, Azure ML, Cognitive Services. Enterprise companies ke liye popular choice.

SERVERLESS

Server manage karne ki zaroorat nahi. Aap sirf code likho, baaki scaling, deployment sab auto hota hai. Cost sirf use ke time lagta hai.

Platform Comparison

comparison
Feature AWS GCP Azure
-----------------------------------------------------------------
Serverless Lambda Cloud Run / Functions Azure Functions
Container ECS / EKS GKE AKS
AI/ML Platform SageMaker Vertex AI Azure ML
Free Tier 12 months $300 credit $200 credit
Best For All-round Data/ML heavy .NET / Enterprise

AWS Lambda � Serverless Deployment

AWS Lambda ek serverless compute service hai. Aap sirf function likhte ho, AWS baaki sab handle karta hai � servers, scaling, patches sab.

python
import json

def lambda_handler(event, context):
 """AWS Lambda entry point"""
 body = json.loads(event['body'])
 text = body.get('text', '')
 
 # Simple sentiment analysis
 positive_words = ["good", "great", "awesome", "love", "happy"]
 negative_words = ["bad", "hate", "sad", "terrible", "worst"]
 
 text_lower = text.lower()
 
 pos_count = sum(1 for w in positive_words if w in text_lower)
 neg_count = sum(1 for w in negative_words if w in text_lower)
 
 if pos_count > neg_count:
 sentiment = "positive"
 elif neg_count > pos_count:
 sentiment = "negative"
 else:
 sentiment = "neutral"
 
 confidence = min(0.95, 0.6 + (abs(pos_count - neg_count) * 0.1))
 
 return {
 'statusCode': 200,
 'headers': {
 'Content-Type': 'application/json',
 'Access-Control-Allow-Origin': '*'
 },
 'body': json.dumps({
 'sentiment': sentiment,
 'confidence': round(confidence, 2),
 'text_analyzed': text[:100]
 })
 }
Important: Lambda function ka maximum runtime 15 minutes hai. Agar aapka AI model long running hai toh ECS ya EC2 better option hai.

GCP Cloud Run � Container-based Deployment

Cloud Run aapke Docker containers ko serverless tarike se run karta hai. Koi bhi language, koi bhi framework � sabkaam karta hai.

bash
# Step 1: Dockerfile banao
cat > Dockerfile <
Pro Tip: Cloud Run automatically containers ko scale karta hai � zero se lekar thousands tak. Billing sirf request ke time hoti hai.

Azure Functions � Microsoft ka Serverless

Azure Functions bhi Lambda jaisa serverless hai. Agar aap .NET ya Microsoft ecosystem use karte ho toh ye best choice hai.

python
import azure.functions as func
import json

app = func.FunctionApp()

@app.route(route="analyze", methods=["POST"])
def analyze_text(req: func.HttpRequest) -> func.HttpResponse:
 """Azure Function for text analysis"""
 try:
 body = req.get_json()
 text = body.get('text', '')
 
 # Word count and basic analysis
 words = text.split()
 word_count = len(words)
 
 # Sentiment check
 positive = ["good", "great", "love", "amazing"]
 neg_count = sum(1 for w in text.lower().split() if w in ["bad", "hate", "terrible"])
 pos_count = sum(1 for w in text.lower().split() if w in positive)
 
 result = {
 'word_count': word_count,
 'sentiment': 'positive' if pos_count > neg_count else 'negative' if neg_count > pos_count else 'neutral',
 'status': 'success'
 }
 
 return func.HttpResponse(
 json.dumps(result),
 mimetype="application/json",
 status_code=200
 )
 except Exception as e:
 return func.HttpResponse(
 json.dumps({'error': str(e)}),
 mimetype="application/json",
 status_code=400
 )
bash
# Azure Functions deploy
func azure functionapp publish 

# Ya Azure CLI se
az functionapp deployment source config-zip \
 --resource-group myRG \
 --name myFunctionApp \
 --src function-app.zip

Deployment Steps � Kaise Deploy Karein?

STEP 1

Code Prepare Karo � Apna code clean karo, requirements.txt banao, environment variables set karo. Docker image banao agar container deploy kar rahe ho.

STEP 2

Platform Choose Karo � AWS Lambda (serverless), Cloud Run (containers), ya Azure Functions (Microsoft ecosystem) � jo aapke use case ke liye best ho.

STEP 3

Deploy Karo � CLI commands ya console se deploy karo. Environment variables, API keys, sab set karo. Test karo ki sab kaam kar raha hai.

STEP 4

Monitor & Scale � Logs check karo, errors fix karo, performance monitor karo. Auto-scaling enable karo traffic handle karne ke liye.

Cost Estimation

Free Tier Limits:
  • AWS Lambda: 1 million requests/month free (12 months)
  • GCP Cloud Run: 2 million requests/month free always
  • Azure Functions: 1 million requests/month free (always free)
pricing
Feature AWS Lambda Cloud Run Azure Functions
-------------------------------------------------------------
Per 1M requests $0.20 $0.40 $0.20
Per GB-second $0.0000166 $0.0000240 $0.0000160
Free tier 400K GB-sec 180K GB-sec 400K GB-sec

Practice Exercise

Quick check

AWS Lambda kya hai✓ Iska basic definition do.

Sochlo: server +less = server manage nahi karna. Code run karna hai bus.

Cloud Deployment complete?

Ab MLOps par chalo � jahan aap seekhoge ML models ko production mein kaise manage karte hain.