Edge Functions is a serverless compute layer that runs custom TypeScript code without requiring you to manage servers. Use it to build authenticated API endpoints, call large language model (LLM) APIs, validate data before writing to your database, or proxy third-party services that require server-side credentials.
PolarDB Supabase provides full Edge Functions support through a self-developed Function as a Service (FaaS) management system. Your function code is stored in your private repository, and metadata is stored in your PolarDB for PostgreSQL cluster.
How it works
Each Edge Functions request follows this path:
-
Request arrives — your client calls the function's invocation URL (
http://<instance-address>/functions/<version>/<function-name>). -
Routing — the gateway routes the request to the appropriate function.
-
Function executes — the Deno runtime spawns a V8 Isolates sandbox for the request. Each sandbox runs in complete memory and scope isolation, with cold starts in the millisecond range.
-
Data access — your function calls Supabase services (database, authentication, storage) or external APIs directly, without extra connection configuration.
-
Response returns — the function returns its result to the client.
PolarDB Supabase cannot access the internet by default. Configure an Internet NAT gateway before your functions call any external APIs.
Use cases
-
AI integration: Call LLM APIs (such as OpenAI) to add content generation, summarization, semantic search, or content moderation to your app.
-
Data validation: Run complex validation logic, permission checks, or format transformations before writing to the database.
-
Secure API proxy: Encapsulate calls to third-party services that require sensitive API keys or are restricted by CORS — keeping credentials off the client.
-
API aggregation: Merge responses from multiple database queries or external services into a single response, reducing the number of round trips.
-
Privileged operations: Provide a secure middle layer for deletions or high-privilege writes, preventing direct client access to risky operations.
Key concepts
Runtime and isolation
Edge Functions runs on Deno with V8 Isolates. Each request executes in its own sandbox with full memory and scope isolation. Cold starts are in the millisecond range.
TypeScript support
Write and deploy .ts files directly. No build tools such as Webpack are required.
FaaS management
The open source Supabase distribution includes the Edge Functions runtime but not the FaaS management backend — meaning self-hosted Supabase can simulate functions locally but cannot deploy them through Studio or the CLI. PolarDB Supabase replaces this with a self-developed FaaS management system, giving you full deployment capability.
Deployment formats
| Format | Contents | Dependency handling |
|---|---|---|
eszip |
Single executable file with all dependencies bundled | None — ready to run |
zip |
Source code only | Server-side packaging after upload |
When you deploy via the online editor in Studio, dependencies are handled automatically.
Limits
-
Each function execution has a maximum runtime duration and memory limit.
-
Internet access is disabled by default. Configure an Internet NAT gateway to enable outbound calls.
Prerequisites
Before you begin, make sure you have:
-
A PolarDB Supabase application
-
Permissions to create NAT gateways and configure SNAT rules in your VPC
Deploy Edge Functions
Step 1: Configure an Internet NAT gateway
To enable internet access for PolarDB Supabase, create a NAT gateway in the same VPC and vSwitch as your PolarDB for PostgreSQL cluster, then configure an SNAT entry.
-
Go to the NAT Gateway - Internet NAT Gateway purchase page and create an Internet NAT gateway. Select the same VPC and vSwitch as your PolarDB for PostgreSQL cluster.
-
Go to the Internet NAT Gateway page. In the Actions column of the gateway, click Configure SNAT, then click Create SNAT Entry. Set the following parameters:
Parameter Value SNAT Entry Granularity VPC-level Select Elastic IP Address Select the elastic IP address (EIP) that provides internet access
Step 2: Mount storage (optional)
If storage was automatically mounted when you created the PolarDB Supabase application, skip this step. Mounting storage restarts the application — plan accordingly.
Edge Functions stores packaged code files in a storage instance. If one was not mounted automatically, mount it now.
-
Log on to the PolarDB console. On the cluster details page, go to AI Capabilities > AI Applications and find your PolarDB Supabase application.
-
In the Dependent Resources column, click Mount Storage. On the Select Cold Storage Directory page, configure the following:
-
Cold Storage Instance ID: Select an existing cold storage instance, or click Create Directory to create one with these parameters:
Parameter Description Storage Class Locally redundant storage: data is redundant within a single zone. Zone-redundant storage: data is redundant across multiple zones. UID Your Alibaba Cloud account UID PolarFS AK and PolarFS SK Your Alibaba Cloud account AccessKey ID and AccessKey Secret
-
Step 3: Configure application parameters
Modifying parameters restarts the PolarDB Supabase application — plan accordingly.
Update the application's URL parameters so that the Edge Functions invocation URLs resolve correctly.
-
Log on to the PolarDB console. On the cluster details page, go to AI Capabilities > AI Applications and find your PolarDB Supabase application.
-
Click your Application ID to open the application details page. On the Configuration tab, replace
auth.GOTRUE_SITE_URL,studio.SUPABASE_PUBLIC_URL, andauth.API_EXTERNAL_URLwith your application endpoint.
Step 4: Create a function
-
Log on to the PolarDB console. On the cluster details page, go to AI Capabilities > AI Applications and find your PolarDB Supabase application.
-
Connect to the Supabase application. In the left navigation pane, go to Edge Functions and click Deploy a new function.
-
Create the function using one of the following methods:
-
Via Editor: Write or paste your TypeScript code directly in the built-in browser editor.
-
Via Upload: Upload a local package in
esziporzipformat.
-
-
Enter a Function Name and click Deploy Function.
Step 5: Invoke the function
After deployment, the system generates a unique invocation URL in the following format:
http://<Your Supabase instance public address>/functions/<version number>/<your function name>
To find the URL for a deployed function:
-
Log on to the PolarDB console. On the cluster details page, go to AI Capabilities > AI Applications and find your PolarDB Supabase application.
-
Connect to the Supabase application. In the left navigation pane, go to Edge Functions. The invocation URL for each function is listed in the URL column.
Troubleshooting
Function cannot reach external APIs
The function call succeeds but external API requests time out or fail. Internet access is not enabled. Configure an Internet NAT gateway and SNAT entry as described in Step 1.
Deployment fails after mounting storage
If the application restarted during storage mounting (Step 2), wait for the restart to complete before retrying the deployment.
Application parameters not taking effect
If auth.GOTRUE_SITE_URL, studio.SUPABASE_PUBLIC_URL, or auth.API_EXTERNAL_URL were not updated (Step 3), function invocation URLs may be incorrect. On the Configuration tab, verify that all three values match your application endpoint.