Why Supabase Edge Functions?
Supabase Edge Functions let you deploy TypeScript functions to Deno Deploy's global edge network — zero server management, sub-50ms cold starts, and native access to your Supabase database.
While AWS Lambda requires complex IAM roles and API Gateway configs, Supabase gives you supabase functions deploy and you're live.
Quick Start
npx supabase init
npx supabase functions new hello-world
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"
import { createClient } from "https://esm.sh/@supabase/supabase-js@2"
serve(async (req) => {
const supabase = createClient(
Deno.env.get("SUPABASE_URL")!,
Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!
)
const { data, error } = await supabase
.from("users")
.select("*")
.limit(10)
return new Response(JSON.stringify({ data, error }), {
headers: { "Content-Type": "application/json" },
})
})
Deploy in Seconds
supabase functions deploy hello-world
Your function runs globally on Deno Deploy's 35+ edge locations.
Real Use Cases
Webhook handler:
serve(async (req) => {
const payload = await req.json()
if (payload.type === "checkout.session.completed") {
const supabase = createClient(
Deno.env.get("SUPABASE_URL")!,
Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!
)
await supabase
.from("orders")
.update({ status: "paid" })
.eq("stripe_session_id", payload.data.object.id)
}
return new Response("ok")
})
Image resizer:
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"
serve(async (req) => {
const url = new URL(req.url)
const imageUrl = url.searchParams.get("url")
const width = url.searchParams.get("w") || "400"
const response = await fetch(
`https://images.weserv.nl/?url=${imageUrl}&w=${width}&output=webp`
)
return new Response(response.body, {
headers: { "Content-Type": "image/webp", "Cache-Control": "public, max-age=31536000" }
})
})
Edge Functions vs Alternatives
| Feature | Supabase Edge | AWS Lambda | Vercel Functions |
|---|---|---|---|
| Cold start | <50ms | 100-500ms | 50-250ms |
| Language | TypeScript/Deno | Any | Node.js/Python |
| DB access | Native | Via SDK | Via SDK |
| Pricing | 500K/mo free | 1M/mo free | 100K/mo free |
| Deploy | 1 command | SAM/CDK | Git push |
The Killer Feature: Database Integration
Edge Functions have native access to your Supabase Postgres database, Auth, Storage, and Realtime — no extra config. Environment variables are auto-injected.
Need to extract data from any website at scale? I build custom web scrapers — 77 production scrapers running on Apify Store. Email me at spinov001@gmail.com for a tailored solution.
Check out my awesome-web-scraping collection — 400+ tools for extracting web data.
Top comments (0)