AnalyticDB for PostgreSQL Supabase (AnalyticDB Supabase) Edge Functions is a fully managed edge computing service that lets you deploy TypeScript Deno functions to your AnalyticDB Supabase projects. Unlike the open-source, self-hosted version of Supabase, AnalyticDB Supabase provides fully managed capabilities for Edge Functions. This ensures that your code and data remain under your control while offering a developer experience consistent with Supabase Cloud. This topic describes how to deploy and manage AnalyticDB Supabase Edge Functions and how to configure and centrally manage secrets to help you quickly build secure and controllable edge computing applications.
Feature overview
AnalyticDB Supabase Edge Functions provides a Deno-based edge computing solution. It offers a modern serverless experience for full-stack application developers.
The function management backend for the open-source version of Supabase is not open source. As a result, self-hosted users cannot deploy to a production environment using a graphical user interface or command line interface. AnalyticDB Supabase solves this problem by providing its own Edge Functions management platform. All your code and configuration data reside in your private environment, which makes the feature practical and gives you full control.
In addition, AnalyticDB Supabase provides native configuration and centralized management for Edge Function secrets. You can securely store sensitive information, such as an Alibaba Cloud Model Studio API key, in a key vault and then retrieve it using Deno.env.get. This method prevents you from hard coding sensitive information or exposing it on the client.
Benefits
Native TypeScript development: No compilation or packaging is required. You can deploy TypeScript source code directly, which simplifies the development process.
Ecosystem integration: You can directly access services, such as the Supabase database, user authentication, and Object Storage Service, from within a function without additional configuration.
Isolation and high performance: The sandbox mechanism and Deno security model ensure that each request runs independently. This provides millisecond-level responses and nearly imperceptible cold starts.
Procedure
Deploy an Edge Function
Deploy using the Dashboard
In the sidebar of the Dashboard, choose Edge Function > Functions.
In the upper-right corner of the page, click Deploy a new function and select Via Editor from the drop-down list.

Write your code in the code editor.
ImportantTo import third-party dependencies or call public network APIs in a function, you must enable public network access for the AnalyticDB for PostgreSQL Supabase project.
The following example includes
index.ts(the entry file) and foo.ts.The
index.tsfile is as follows:import { foo } from './foo.ts'; console.info('server started'); Deno.serve(async (req)=>{ const { name } = await req.json(); const data = { message: `Hello ${foo()} ${name}!` }; return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json', 'Connection': 'keep-alive' } }); });The
foo.tsfile is as follows:export function foo() { return 'bar'; }
In the lower-right corner, edit the name of the Edge Function, and then click Deploy.
Deploy using the functions-cli tool
Obtain and configure the
SUPABASE_API_URLandSUPABASE_API_KEYfor the target project.The
SUPABASE_API_KEYis the service role key. For more information about how to obtain the configuration information, see Get API Keys. You can configure the key in the following ways:Environment variable:
export SUPABASE_API_KEY=xxx.envfile:SUPABASE_API_KEY=xxxCommand line parameter:
-key xxx
The following example shows how to configure the key using an environment variable:
export SUPABASE_API_URL=https://sbp-xxx.supabase.opentrust.net export SUPABASE_API_KEY=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoic2VxxxxPrepare the function files.
This topic uses the following function folder structure, which includes
index.ts(the entry file) andfoo.ts.supabase └── functions └── hello ├── foo.ts └── index.tsThe
index.tsfile is as follows:import { foo } from './foo.ts'; console.info('server started'); Deno.serve(async (req)=>{ const { name } = await req.json(); const data = { message: `Hello ${foo()} ${name}!` }; return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json', 'Connection': 'keep-alive' } }); });The
foo.tsfile is as follows:export function foo() { return 'bar'; }
Download the functions-cli tool. When you run the following commands, replace
functions-cliwith the name of the downloaded CLI tool.Run the deployment command.
./functions-cli deploy helloNoteThe deployment command searches for the
supabase/functions/path in the current directory and looks for a function folder namedhello.If the "At least one file is required" error occurs, log on to the console. In the Actions column for the target Supabase project, choose and then retry the operation. If your project version is v1.0.0, the database connection string is updated after the upgrade.
Test an Edge Function
Test using the Dashboard
In the upper-right corner of the Functions page, click the Test button.

In the panel, click Send Request in the lower-right corner.

Test using a curl command
On the Details tab, copy the curl command and replace [YOUR ANON KEY] with the anon key or service role key.

The following is an example response:

Update an Edge Function
In the sidebar of the Dashboard, choose Edge Function > Functions, and then click the target function.

Click the Code tab and edit the target file.
In the lower-right corner, click the Deploy updates button to update the Edge Function.

Migrate an Edge Function
Migrate from Supabase Cloud to AnalyticDB Supabase
Step 1: Get and configure project information
Obtain the personal access token for the source.
Go to the Supabase Cloud console.
On the Access Tokens page, click Generate new token.

Enter a token name and click Generate token.

Copy and securely store the token.
Obtain the Project Ref for the source.
Go to the Supabase console.
Click the source project and view the URL. The string at the end of the URL is the Project Ref. For example, if the URL is
https://supabase.com/dashboard/project/qeqfhfoebrtkbmwd****, the Project Ref isqeqfhfoebrtkbmwd****.
Obtain the
SUPABASE_API_URLandSUPABASE_API_KEYfor the target project. TheSUPABASE_API_KEYis the service role key. For more information about how to obtain the keys, see Get API Keys.(Optional) Configure the project information. You can configure the information in one of the following ways:
Environment variable:
export SUPABASE_API_KEY=xxx.envfile:SUPABASE_API_KEY=xxxCommand line parameter:
-key xxx
The following example shows how to configure the information using environment variables:
export SUPABASE_SOURCE_REF=abcdefghijkl**** export SUPABASE_SOURCE_TOKEN=sbp_1760f47cc82fe3466dce9aa********* export SUPABASE_API_URL=https://sbp-xxx.supabase.opentrust.net export SUPABASE_API_KEY=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoic2V****
Step 2: Install Deno
For more information, see the installation instructions.
Step 3: Migrate using functions-cli
Download the functions-cli tool. When you run the following commands, replace
functions-cliwith the name of the downloaded CLI tool.Run the migration command.
Migrate a single function
Migrate a specific function by its slug:
# Basic usage ./functions-cli migrate \ -s hello \ --source-ref abcdefghijkl**** \ --source-token sbp_1a2b3c4d5e6f7g8h**** \ --target-key eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoic2V**** \ --target-url https://sbp-****.supabase.opentrust.netMigrate all functions
./functions-cli migrate \ --all \ --source-ref abcdefghijkl**** \ --source-token sbp_1a2b3c4d5e6f7g8h**** \ --target-key eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoic2V**** \ --target-url https://sbp-****.supabase.opentrust.net
Sync between AnalyticDB Supabase projects
Step 1: Get and configure project information
Obtain the
SUPABASE_API_URLandSUPABASE_API_KEYfor the source and target projects. TheSUPABASE_API_KEYis the service role key. For more information about how to obtain the keys, see Get API Keys.(Optional) Configure the project information. You can configure the information in one of the following ways:
Environment variable:
export SUPABASE_API_KEY=xxx.envfile:SUPABASE_API_KEY=xxxCommand line parameter:
-key xxx
The following example shows how to configure the information using environment variables:
export SOURCE_API_URL=https://sbp-source***.supabase.opentrust.net export SOURCE_API_KEY=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoic2V**** export SUPABASE_API_URL=https://sbp-target***.supabase.opentrust.net export SUPABASE_API_KEY=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoic2V****
Step 2: Install Deno
For more information, see the installation instructions.
Step 3: Sync using functions-cli
Download the functions-cli tool. When you run the following commands, replace
functions-cliwith the name of the downloaded CLI tool.Run the sync command.
Sync a single function
Sync a specific function by its slug:
./functions-cli sync \ -s hello \ --source-key eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1Ni**** \ --source-url https://sbp-source***.supabase.opentrust.net \ --target-key eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1Ni**** \ --target-url https://sbp-target***.supabase.opentrust.netSync all functions
./functions-cli sync \ --all \ --source-key eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.source_key_**** \ --source-url https://sbp-source****.supabase.opentrust.net \ --target-key eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.target_key_**** \ --target-url https://sbp-target****.supabase.opentrust.net
Delete an Edge Function
In the sidebar of the Dashboard, choose Edge Function > Functions, and then click the target function.
Click the Details tab.
In the Delete function area, click the Delete edge function button. In the dialog box that appears, click the Delete button.

Secrets management
In AnalyticDB Supabase, Alibaba Cloud provides native configuration and centralized management for Edge Function secrets. You can securely store sensitive information in the key vault of the function's runtime environment and then retrieve it using Deno.env.get. This method prevents you from hard coding sensitive information or exposing it on the client.
Default secrets
Edge Functions can access the following secrets by default:
Name | Description |
SUPABASE_URL | The API gateway address of the AnalyticDB Supabase project. |
SUPABASE_ANON_KEY | The anonymous key for the AnalyticDB Supabase API. When Row Level Security is enabled, this key can be safely used in a browser. |
SUPABASE_SERVICE_ROLE_KEY | The service role key for the AnalyticDB Supabase API. This key can be safely used in Edge Functions, but do not use it in a browser. This key bypasses Row Level Security restrictions. |
Create custom secrets
In the sidebar of the Dashboard, choose Edge Function > Secrets.
Enter the key and value.

Click Save.
Get secrets in an Edge Function
You can use Deno's built-in handler to access an environment variable by passing its name. For an example scenario, see Integrate with AI services.
Deno.env.get('NAME_OF_SECRET')