All Products
Search
Document Center

AnalyticDB:Use Edge Functions in AnalyticDB Supabase

Last Updated:Jan 13, 2026

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

  1. Log on to the Supabase Dashboard.

  2. In the sidebar of the Dashboard, choose Edge Function > Functions.

  3. In the upper-right corner of the page, click Deploy a new function and select Via Editor from the drop-down list.

    image

  4. Write your code in the code editor.

    Important

    To 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.ts file 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.ts file is as follows:

      export function foo() {
        return 'bar';
      }
  5. In the lower-right corner, edit the name of the Edge Function, and then click Deploy.

Deploy using the functions-cli tool

  1. Obtain and configure the SUPABASE_API_URL and SUPABASE_API_KEY for the target project.

    The SUPABASE_API_KEY is 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

    • .env file: SUPABASE_API_KEY=xxx

    • Command 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.eyJyb2xlIjoic2Vxxxx
  2. Prepare the function files.

    This topic uses the following function folder structure, which includes index.ts (the entry file) and foo.ts.

    supabase
    └── functions
        └── hello
            ├── foo.ts
            └── index.ts
    • The index.ts file 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.ts file is as follows:

      export function foo() {
        return 'bar';
      }
  3. Download the functions-cli tool. When you run the following commands, replace functions-cli with the name of the downloaded CLI tool.

  4. Run the deployment command.

    ./functions-cli deploy hello
    Note
    • The deployment command searches for the supabase/functions/ path in the current directory and looks for a function folder named hello.

    • 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 More > Upgraded Version 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

  1. In the upper-right corner of the Functions page, click the Test button.

    image

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

    image

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.

image

The following is an example response:

image

Update an Edge Function

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

    image

  2. Click the Code tab and edit the target file.

  3. In the lower-right corner, click the Deploy updates button to update the Edge Function.

    image

Migrate an Edge Function

Migrate from Supabase Cloud to AnalyticDB Supabase

Step 1: Get and configure project information

  1. Obtain the personal access token for the source.

    1. Go to the Supabase Cloud console.

    2. On the Access Tokens page, click Generate new token.

      image

    3. Enter a token name and click Generate token.

      image

    4. Copy and securely store the token.

  2. Obtain the Project Ref for the source.

    1. Go to the Supabase console.

    2. 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 is qeqfhfoebrtkbmwd****.

  3. Obtain the SUPABASE_API_URL and SUPABASE_API_KEY for the target project. The SUPABASE_API_KEY is the service role key. For more information about how to obtain the keys, see Get API Keys.

  4. (Optional) Configure the project information. You can configure the information in one of the following ways:

    • Environment variable: export SUPABASE_API_KEY=xxx

    • .env file: SUPABASE_API_KEY=xxx

    • Command 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

  1. Download the functions-cli tool. When you run the following commands, replace functions-cli with the name of the downloaded CLI tool.

  2. 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.net

    Migrate 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

  1. Obtain the SUPABASE_API_URL and SUPABASE_API_KEY for the source and target projects. The SUPABASE_API_KEY is the service role key. For more information about how to obtain the keys, see Get API Keys.

  2. (Optional) Configure the project information. You can configure the information in one of the following ways:

    • Environment variable: export SUPABASE_API_KEY=xxx

    • .env file: SUPABASE_API_KEY=xxx

    • Command 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

  1. Download the functions-cli tool. When you run the following commands, replace functions-cli with the name of the downloaded CLI tool.

  2. 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.net

    Sync 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

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

  2. Click the Details tab.

  3. In the Delete function area, click the Delete edge function button. In the dialog box that appears, click the Delete button.

    image

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

  1. In the sidebar of the Dashboard, choose Edge Function > Secrets.

  2. Enter the key and value.

    image

  3. 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')