Skip to content
Edge Functions

区域调用

Execute Edge Functions in specific regions for optimal performance.

Edge 函数会自动在离发出请求的用户最近的地区执行。这可以减少网络延迟,并提供更快的响应。

🌐 Edge Functions automatically execute in the region closest to the user making the request. This reduces network latency and provides faster responses.

不过,如果你的函数执行的是大量数据库或存储操作,在与你的数据库相同的区域运行通常能提供更好的性能:

🌐 However, if your function performs intensive database or storage operations, executing in the same region as your database often provides better performance:

  • 批量数据库操作: 添加或编辑大量记录
  • 文件上传: 处理大文件或多个上传
  • 复杂查询: 需要多次访问数据库的操作

可用地区 #

🌐 Available regions

支持以下地区:

🌐 The following regions are supported:

亚太地区:

  • ap-northeast-1(东京)
  • ap-northeast-2(首尔)
  • ap-south-1(孟买)
  • ap-southeast-1(新加坡)
  • ap-southeast-2(悉尼)

北美:

  • ca-central-1(加拿大中部)
  • us-east-1(北弗吉尼亚)
  • us-west-1(北加州)
  • us-west-2(俄勒冈州)

欧洲:

  • eu-central-1(法兰克福)
  • eu-central-2(苏黎世)
  • eu-west-1(爱尔兰)
  • eu-west-2(伦敦)
  • eu-west-3(巴黎)

南美洲:

  • 'sa-east-1'(圣保罗)

用法 #

🌐 Usage

你可以使用 Supabase 客户端库以编程方式指定区域,或者使用 x-region HTTP 头。

🌐 You can specify the region programmatically using the Supabase Client library, or using the x-region HTTP header.

1
import { createClient, FunctionRegion } from '@supabase/supabase-js'
2
3
const { data, error } = await supabase.functions.invoke('function-name', {
4
...
5
region: FunctionRegion.UsEast1, // Execute in us-east-1 region
6
})

如果你无法在请求中添加 x-region 头(例如:CORS 请求、Webhook),你可以使用 forceFunctionRegion 查询参数。

🌐 In case you cannot add the x-region header to the request (e.g.: CORS requests, Webhooks), you can use forceFunctionRegion query parameter.


区域运行时信息 #

🌐 Region runtime information

函数可以访问以下环境变量:

🌐 Functions have access to the following environment variables:

SB_REGION:已调用 AWS 区域功能

🌐 SB_REGION: The AWS region function was invoked

如果你读过 replicate 并且想根据地区连接到不同的 replicate,这会很有用。

🌐 This is useful if you have read replicate and want to Postgres connect to a different replicate according of the Region.


地区停电 #

🌐 Region outages

当你通过 x-region 头显式指定一个区域时,请求不会被自动重定向到其他区域。

🌐 When you explicitly specify a region via the x-region header, requests will NOT be automatically re-routed to another region.

在中断期间,可以考虑暂时切换到其他地区。

🌐 During outages, consider temporarily changing to a different region.