Use the DescribeRegions API to retrieve public, internal, and acceleration endpoints for all supported regions or a specific region—without needing an existing bucket.
Endpoint types
Each OSS region exposes three endpoint types:
| Type | Field in response | When to use |
|---|---|---|
| Public endpoint | InternetEndpoint | Access OSS from the internet |
| Internal endpoint | InternalEndpoint | Access OSS from another Alibaba Cloud service in the same region (VPC or classic network), avoiding data transfer costs |
| Acceleration endpoint | AccelerateEndpoint | Upload and download across all regions with accelerated transfer |
For a full list of regions and their endpoints, see OSS regions and endpoints.
Prerequisites
Before you begin, make sure you have:
OSS SDK for Go 2.0 installed:
go get github.com/aliyun/alibabacloud-oss-go-sdk-v2/ossOSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables set with valid AccessKey credentials. See Configure access credentials
Query endpoints for all regions
Pass an empty DescribeRegionsRequest to retrieve endpoints for every supported region. No bucket is required.
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
var (
region string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the bucket is located. Required.")
}
func main() {
flag.Parse()
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
// Credentials are read from the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET
// environment variables, so no secrets are hardcoded.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := oss.NewClient(cfg)
// No Regions filter means all supported regions are returned.
request := &oss.DescribeRegionsRequest{}
result, err := client.DescribeRegions(context.TODO(), request)
if err != nil {
log.Fatalf("failed to describe regions %v", err)
}
for _, region := range result.RegionInfoList.RegionInfos {
log.Printf("region:%s, public endpoint:%s, internal endpoint:%s, acceleration endpoint:%s\n",
*region.Region, *region.InternetEndpoint, *region.InternalEndpoint, *region.AccelerateEndpoint)
}
}Query endpoints for a specific region
Set the Regions field to the OSS region ID (in the format oss-<region-id>) to get endpoints for that region only.
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
var (
region string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the bucket is located. Required.")
}
func main() {
flag.Parse()
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
// Credentials are read from the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET
// environment variables, so no secrets are hardcoded.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := oss.NewClient(cfg)
// Set Regions to the OSS region ID to filter results to a single region.
// Replace "oss-cn-hangzhou" with the OSS region ID for your target region.
request := &oss.DescribeRegionsRequest{
Regions: oss.Ptr("oss-cn-hangzhou"),
}
result, err := client.DescribeRegions(context.TODO(), request)
if err != nil {
log.Fatalf("failed to describe regions %v", err)
}
for _, region := range result.RegionInfoList.RegionInfos {
log.Printf("region:%s, public endpoint:%s, internal endpoint:%s, acceleration endpoint:%s\n",
*region.Region, *region.InternetEndpoint, *region.InternalEndpoint, *region.AccelerateEndpoint)
}
}