Alibabacloud Sdk Client Initialization For Golang
Initialize and manage Alibaba Cloud SDK clients in Go. Covers sync.Once singleton, goroutine safety, endpoint vs region configuration, VPC endpoints, and deb...
alibabacloud
@sdk-team
Install
$ openclaw skills install @sdk-team/alibabacloud-sdk-client-initialization-for-golangClient Initialization Best Practices (Go)
Core Rules
- Client is goroutine-safe — safe to share across goroutines without additional synchronization.
- Use singleton pattern — do NOT create new client instances per request. Frequent client creation wastes resources.
- Prefer explicit endpoint over region-based endpoint resolution.
Recommended Client Creation
import (
"os"
"sync"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
ecs "github.com/alibabacloud-go/ecs-20140526/v3/client"
"github.com/alibabacloud-go/tea/tea"
)
var (
ecsClient *ecs.Client
ecsClientOnce sync.Once
)
func GetEcsClient() *ecs.Client {
ecsClientOnce.Do(func() {
config := &openapi.Config{
AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
Endpoint: tea.String("ecs.cn-hangzhou.aliyuncs.com"),
}
var err error
ecsClient, err = ecs.NewClient(config)
if err != nil {
panic(err)
}
})
return ecsClient
}
Endpoint Configuration
Priority: explicit Endpoint > region-based resolution via RegionId.
// Preferred: explicit endpoint
config.Endpoint = tea.String("ecs.cn-hangzhou.aliyuncs.com")
// Alternative: SDK resolves endpoint from region
config.RegionId = tea.String("cn-hangzhou")
VPC Endpoints
Use VPC endpoints when running inside Alibaba Cloud VPC:
config.Endpoint = tea.String("ecs-vpc.cn-hangzhou.aliyuncs.com")
File Upload APIs (Advance)
Set both RegionId and Endpoint to the same region for file upload APIs:
config.RegionId = tea.String("cn-shanghai")
config.Endpoint = tea.String("objectdet.cn-shanghai.aliyuncs.com")
// VPC file upload authorization:
client.OpenPlatformEndpoint = tea.String("openplatform-vpc.cn-shanghai.aliyuncs.com")
client.EndpointType = tea.String("internal")
SDK Components
| Component | Description |
|---|---|
Core SDK (darabonba-openapi) | Generic calls, no product dependency |
Product SDK (e.g., ecs-20140526) | Typed client, models, convenience methods |
Debugging
Enable debug mode via environment variable to log all requests:
export DEBUG=tea
Top skills in this category
Skill Vetter
@spclaudehomeSecurity-first skill vetting for AI agents. Use before installing any skill from ClawdHub, GitHub, or other sources. Checks for red flags, permission scope, and suspicious patterns.
Github
@steipeteInteract with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Humanizer
@biostartechnologyRemove signs of AI-generated writing from text. Use when editing or reviewing text to make it sound more natural and human-written. Based on Wikipedia's comprehensive "Signs of AI writing" guide. Detects and fixes patterns including: inflated symbolism, promotional language, superficial -ing analyses, vague attributions, em dash overuse, rule of three, AI vocabulary words, negative parallelisms, and excessive conjunctive phrases.
Free Ride - Unlimited free AI
@shaivpidadiManages free AI models from OpenRouter for OpenClaw. Automatically ranks models by quality, configures fallbacks for rate-limit handling, and updates opencla...
Elite Longterm Memory
@nextfrontierbuildsUltimate AI agent memory system for Cursor, Claude, ChatGPT & Copilot. WAL protocol + vector search + git-notes + cloud backup. Never lose context again. Vibe-coding ready.