Updated Nov 20, 20267 min read

How to Migrate Supabase Edge Functions to AWS

A step-by-step guide to moving Supabase Edge Functions to AWS: what changes when Deno handlers become Node.js code, how to keep verifying Supabase Auth tokens, where background tasks go, and a TypeScript version with the endpoints, queue and database in your own AWS account.

Illustration for How to Migrate Supabase Edge Functions to AWS

Supabase Edge Functions are TypeScript handlers on Deno, a quick way to add a webhook or an invite flow next to a Supabase database. They get tight past 2 seconds of CPU or 256 MB of memory per request, or when background work has to survive a restart.

Moving them to AWS is mostly a port from Deno to Node.js plus a decision about auth, and this guide covers both.

How do Edge Functions map to AWS?

Supabase Edge FunctionsAWS
RuntimeDeno, Deno.serve handlerLambda on Node.js, or a container on ECS Fargate
URLhttps://<ref>.supabase.co/functions/v1/<name>Lambda function URL, API Gateway or a load balancer
AuthJWT checked before the function runs, unless turned offIAM or no auth on function URLs, so the JWT check moves into your code
Importsnpm: and jsr: specifierspackage.json dependencies
Secretssupabase secrets set, read with Deno.env.getSecrets Manager or SSM, read at startup
Background workEdgeRuntime.waitUntilSQS with a consumer
Limits2 s CPU per request, 256 MB, 150 s idle timeoutLambda: 15 minutes and up to 10,240 MB; Fargate: no request limit

The Edge Functions limits are from Supabase's limits page, checked on November 20, 2026. Lambda's are in the Lambda quotas, and function URLs support only AWS_IAM or NONE as the auth type, per the function URL docs.

Step 1: List the functions and what they touch

Run supabase functions list and, for each function, note its trigger (called from the browser with the user's session, called by a database webhook, or called by a third party such as Stripe), the secrets it reads, the tables it queries through supabase-js and anything it hands to EdgeRuntime.waitUntil. Browser-called functions are the ones that depend on Supabase verifying the JWT for you, and webhook functions usually have JWT verification turned off with --no-verify-jwt and check a signature instead.

Step 2: Port the handler from Deno to Node.js

The request and response objects are the standard Fetch API in both runtimes, so most of the body of a handler carries over. Deno.env.get("RESEND_API_KEY") becomes process.env.RESEND_API_KEY or a value loaded from Secrets Manager, import Stripe from "npm:stripe" becomes a dependency in package.json, and Deno.serve is replaced by whatever your target expects, an exported handler on Lambda or a route in an HTTP server in a container. Functions that only call supabase-js against the database can keep doing so during the move, then switch to a direct Postgres connection once the database moves too, as covered in migrating Supabase Postgres to RDS.

Step 3: Keep verifying Supabase Auth tokens

Supabase checks the JWT before an Edge Function runs, and on AWS that check becomes code. Projects that use asymmetric signing keys publish their public keys at /auth/v1/.well-known/jwks.json, and Supabase's JWT docs describe verifying the signature against that key set, with iss set to the project's auth URL. Access tokens for signed-in users carry aud: "authenticated", which is worth checking along with the issuer and expiry.

Step 4: Move background tasks to a queue

Work passed to EdgeRuntime.waitUntil, such as sending an email after the response, lives as long as the worker does and has no retry if it fails. On AWS, publish a message to a queue in the request and let a consumer do the work, with a dead-letter queue for messages that keep failing, so a slow email provider no longer delays or loses the invite.

Step 5: Run the functions as endpoints in code

Encore brings infrastructure from code, and each Edge Function becomes a typed endpoint in a TypeScript service, with one auth handler in front of all of them and a Pub/Sub topic in place of waitUntil. Per the AWS infrastructure docs, the services run on Fargate, Pub/Sub on SNS and SQS, and the database on RDS, all in your own account, with Encore provisioning an IAM role for the service. There are no function URLs, Secrets Manager entries or queue policies to create by hand.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

The auth handler that replaces Supabase's JWT check, using jose to verify tokens against the project's key set:

// auth/auth.ts import { APIError, Gateway, Header } from "encore.dev/api"; import { authHandler } from "encore.dev/auth"; import { secret } from "encore.dev/config"; import { createRemoteJWKSet, jwtVerify } from "jose"; // For example https://abcdefgh.supabase.co const supabaseUrl = secret("SupabaseUrl"); let jwks: ReturnType<typeof createRemoteJWKSet> | undefined; interface AuthParams { authorization: Header<"Authorization">; } export interface AuthData { userID: string; email: string | null; } export const auth = authHandler<AuthParams, AuthData>(async ({ authorization }) => { const token = authorization?.replace(/^Bearer /, ""); if (!token) throw APIError.unauthenticated("missing bearer token"); const issuer = `${supabaseUrl()}/auth/v1`; jwks ??= createRemoteJWKSet(new URL(`${issuer}/.well-known/jwks.json`)); try { const { payload } = await jwtVerify(token, jwks, { issuer, audience: "authenticated" }); return { userID: String(payload.sub), email: typeof payload.email === "string" ? payload.email : null, }; } catch { throw APIError.unauthenticated("invalid or expired token"); } }); export const gateway = new Gateway({ authHandler: auth });

An invite-member Edge Function as an endpoint, with the email that used to go through EdgeRuntime.waitUntil moved to a subscription:

// teams/teams.ts import { api, APIError } from "encore.dev/api"; import { getAuthData } from "~encore/auth"; import { SQLDatabase } from "encore.dev/storage/sqldb"; import { Topic, Subscription } from "encore.dev/pubsub"; import log from "encore.dev/log"; const db = new SQLDatabase("teams", { migrations: "./migrations" }); interface InviteCreated { inviteID: number; email: string; teamID: number; } export const inviteCreated = new Topic<InviteCreated>("invite-created", { deliveryGuarantee: "at-least-once", }); // Was supabase/functions/invite-member/index.ts. export const inviteMember = api( { expose: true, auth: true, method: "POST", path: "/teams/:teamID/invites" }, async (p: { teamID: number; email: string }): Promise<{ inviteID: number }> => { const { userID } = getAuthData()!; const owner = await db.queryRow` SELECT 1 FROM team_members WHERE team_id = ${p.teamID} AND user_id = ${userID} AND role = 'owner' `; if (!owner) throw APIError.permissionDenied("only team owners can invite"); const row = await db.queryRow<{ id: number }>` INSERT INTO invites (team_id, email, invited_by) VALUES (${p.teamID}, lower(${p.email}), ${userID}) ON CONFLICT (team_id, email) DO UPDATE SET email = EXCLUDED.email RETURNING id `; await inviteCreated.publish({ inviteID: row!.id, email: p.email, teamID: p.teamID }); return { inviteID: row!.id }; }, ); // Replaces EdgeRuntime.waitUntil(sendEmail(...)): retried, and dead-lettered after 5 tries. const _ = new Subscription(inviteCreated, "send-invite-email", { retryPolicy: { maxRetries: 5 }, handler: async (msg) => { const sent = await db.queryRow` UPDATE invites SET emailed_at = now() WHERE id = ${msg.inviteID} AND emailed_at IS NULL RETURNING id `; if (!sent) return; // already emailed by an earlier delivery log.info("sending invite email", { inviteID: msg.inviteID, teamID: msg.teamID }); // Call the email provider here. On failure, reset emailed_at and throw, // so the retry sends it. }, });
-- teams/migrations/1_init.up.sql CREATE TABLE team_members ( team_id BIGINT NOT NULL, user_id UUID NOT NULL, role TEXT NOT NULL CHECK (role IN ('owner', 'member')), PRIMARY KEY (team_id, user_id) ); CREATE TABLE invites ( id BIGSERIAL PRIMARY KEY, team_id BIGINT NOT NULL, email TEXT NOT NULL, invited_by UUID NOT NULL, emailed_at TIMESTAMPTZ, UNIQUE (team_id, email) );

The auth handler runs once at the gateway for every endpoint marked auth: true, which is what Supabase did for each function, and the authentication docs cover how getAuthData reaches the user ID. Set the Supabase URL with encore secret set --type prod SupabaseUrl, as the secrets docs describe, and the value lives in the cloud environment rather than in the repository. With encore run, Postgres starts locally and the subscription receives messages on the first request, and the Pub/Sub docs explain the retry policy that replaces waitUntil.

To deploy, connect your AWS account as described in Connect your cloud account and push with git push encore.

Each former function is a typed endpoint in the same repository as the database schema and the queue, so a coding agent that changes the invite flow edits one service, runs it locally against a real Postgres and sees the email subscription fire in the trace before it opens a pull request.

Best fit: Teams whose Edge Functions have grown into a backend and who want those endpoints, their queue and their database running in their own AWS account, with Supabase Auth kept for sign-in.

Step 6: Switch callers one function at a time

Point the frontend at the new endpoint for one function, keep the Edge Function deployed as a fallback for a few days, then delete it with supabase functions delete <name>. For database webhooks that called an Edge Function, change the webhook URL to the new endpoint, and for third-party webhooks such as Stripe, add the new URL as a second endpoint before removing the old one, so no event lands nowhere.

Frequently asked questions

Can I run Supabase Edge Functions on AWS Lambda?

No. Edge Functions are Deno handlers built around Deno.serve, while Lambda's managed runtimes call an exported handler function, so each function needs a small adapter or a port to Node.js. Imports with npm: or jsr: specifiers become regular package.json dependencies.

How do I verify Supabase Auth tokens outside Supabase?

Fetch the project's public keys from https://<project-ref>.supabase.co/auth/v1/.well-known/jwks.json and verify the token's signature, issuer and audience with a JWT library such as jose. This works for projects that use asymmetric JWT signing keys; projects on the legacy shared secret verify with that secret instead.

What replaces EdgeRuntime.waitUntil on AWS?

Use a queue: publish a message to SQS or a Pub/Sub topic from the request handler and do the slow work in a consumer, which gets retries and a dead-letter queue instead of work that disappears when the worker stops.

How do I move Supabase Edge Functions into a backend on my own AWS account?

With Encore, each function becomes a typed TypeScript endpoint, an auth handler verifies the Supabase token once for every endpoint, and background work goes to a Pub/Sub topic. Deploying to your AWS account provisions the database, topic and services from the same code.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders