All Products
Search
Document Center

AnalyticDB:Use Edge Functions in AnalyticDB Supabase

Last Updated:Jan 21, 2026

AnalyticDB for PostgreSQL Supabase (AnalyticDB Supabase) Edge Functions is a fully managed edge computing service that enables deploying TypeScript/Deno functions to your AnalyticDB Supabase projects. AnalyticDB Supabase provides the same Edge Function management and development experience as open-source Supabase, while ensuring full control over your code and data. This topic guides you through deploying and managing AnalyticDB Supabase Edge Functions, configuring secrets, and building secure, controllable edge applications.

Overview

AnalyticDB Supabase Edge Functions provides a Deno-based edge computing solution. It offers a modern serverless experience for full-stack application developers.

The open source community version of Supabase does not include a function management backend. Therefore, self-hosted users cannot deploy to a production environment using a graphical user interface (GUI) or a command line interface (CLI). AnalyticDB Supabase solves this problem by providing its own Edge Functions management platform. All your code and configuration data reside in your private environment. This makes the feature usable in a production environment and gives you full control.

In addition, AnalyticDB Supabase provides native configuration and central 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 avoids hard coding or exposing information 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 extra configuration.

  • Isolation and high performance: The sandbox mechanism and Deno security model ensure that each request runs independently, which provides millisecond-level responses and nearly imperceptible cold starts.

Procedure

Deploy edge function

Deploy using the Dashboard

  1. Log on to the Supabase Dashboard.

  2. In the sidebar of the Dashboard, click 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, which is 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, enter a name for 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 example uses the following function folder structure, which includes index.ts as 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 and a function directory named hello in the directory from which the command is run.

    • If the error "At least one file is required" occurs, log on to AnalyticDB for PostgreSQL Supabase console. In the Actions column of 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 will be updated after the upgrade.

Test 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 edge function

  1. In the sidebar of the Dashboard, click 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 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 key, 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 Installation.

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 key, 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 Installation.

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, click 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

Manage secrets

In AnalyticDB Supabase, Alibaba Cloud provides native configuration and central 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 avoids hard coding or exposing information on the client.

Default secrets

Edge Functions can access the following secrets by default:

Name

Description

SUPABASE_URL

The API gateway URL of the AnalyticDB Supabase project.

SUPABASE_LOCAL_URL

The local API gateway URL for the AnalyticDB Supabase project (bypasses the public network for lower latency).

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

Create on Dashboard

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

  2. Enter the key and value.

    image

  3. Click Save to add the secret.

Creating with the functions-cli tool

  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 command.

    # Add one secret
    functions-cli secrets set DASHSCOPE_API_KEY=sk_test123456
    
    # Add multiple secrets
    functions-cli secrets set DASHSCOPE_API_KEY=sk_test123456 OPENAI_API_KEY=test123456 
    
    # Add secrets from an .env file
    functions-cli secrets set --env-file supabase/functions/.env

Get secrets in an Edge Function

You can use Deno's built-in handler to access environment variables by passing the name of the environment variable. For a usage scenario, see Integrate with AI services.

Deno.env.get('NAME_OF_SECRET')