π° Serverless on a Budget: Netlify as a Free Alternative to AWS and Azure
Serverless on a Budget: Why I Chose Netlify over AWS and Azure
As a developer working on side projects, I was looking for a cost-effective way to deploy serverless functions without worrying about unexpected cloud bills. After experimenting with AWS Lambda and Azure Functions, I discovered Netlifyβs serverless platform. Hereβs why it became my go-to solution for hobby projects.
The Cost Challenge
Traditional cloud providers can be expensive:
- AWS Lambda: Charges for compute time and requests
- Azure Functions: Complex pricing tiers
- Both require additional services (API Gateway, monitoring) that add up
Enter Netlify
Netlify offers:
- 125K function invocations/month (free tier)
- No credit card required
- Built-in CI/CD
- Automatic HTTPS
- Easy environment variable management
Quick Start: Python Hello World on Netlify
Letβs create a simple Python function that returns a greeting.
1. Project Setup
Create a new directory structure:
netlify-python/
βββ netlify/
β βββ functions/
β βββ hello.py
βββ netlify.toml
βββ .gitignore # For Python and Netlify specific files
Add a .gitignore
file to exclude unnecessary files:
# Python
__pycache__/
*.py[cod]
venv/
.env
# Netlify
.netlify/
.netlify.toml.backup
# Node (for Netlify CLI)
node_modules/
# IDE and OS
.vscode/
.DS_Store
2. Create the Python Function
In netlify/functions/hello.py
:
from http.server import BaseHTTPRequestHandler
from datetime import datetime
class handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
message = {
"message": "Hello from Netlify Functions!",
"timestamp": datetime.now().isoformat()
}
self.wfile.write(json.dumps(message).encode())
return
3. Configure Netlify
Create netlify.toml
:
[build]
functions = "netlify/functions"
[functions]
directory = "netlify/functions"
node_bundler = "esbuild"
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
status = 200
4. Deploy to Netlify
- Install Netlify CLI:
npm install netlify-cli -g
- Login and deploy:
netlify login netlify deploy --prod
Testing Your Function
Once deployed, your function will be available at:
https://your-site-name.netlify.app/.netlify/functions/hello
Cost Comparison
For a simple API with 100K requests/month:
Provider | Cost/Month |
---|---|
AWS | ~$5-10 |
Azure | ~$5-15 |
Netlify | $0 |
Why This Matters
- No Surprise Bills: Fixed, generous free tier
- Simple Deployment: Push to git, auto-deploys
- Complete Solution: Includes SSL, CDN, CI/CD
- Perfect for Learning: No risk of accidental charges
When to Use This Approach
β Perfect for:
- Personal projects
- MVPs
- Learning serverless
- Small to medium APIs
β οΈ Consider paid services when:
- Needing more than 125K invocations/month
- Requiring complex cloud services
- Building enterprise applications
Tips and Best Practices
- Monitor Usage:
- Keep track of function invocations
- Set up notifications when approaching limits
- Optimize Functions:
- Keep dependencies minimal
- Use caching when possible
- Implement proper error handling
- Version Control:
- Use Git for deployment
- Maintain separate dev/prod branches
Conclusion
Netlifyβs free tier is a game-changer for developers who want to experiment with serverless without the stress of cloud costs. While it may not replace AWS or Azure for enterprise needs, itβs perfect for personal projects and learning.
Got questions about migrating your serverless functions to Netlify? Feel free to reach out in the comments!