flipped-aurora/gin-vue-admin · error
function config.LoadDefaultConfig() failed, err:
Error message
function config.LoadDefaultConfig() failed, err:
What it means
newS3Client builds an aws.Config via the AWS SDK's config.LoadDefaultConfig with static credentials; when that call fails, this error wraps the SDK's reason. LoadDefaultConfig itself rarely fails with static credentials, but it can fail when required inputs (region, credential chain) resolve to nothing usable or a shared-config/profile file is malformed.
Source
Thrown at server/utils/upload/aws_s3.go:229
return files, nextCursor, hasMore, nil
}
// newS3Client creates an S3 v2 client with static credentials and optional custom endpoint.
// minio在这里设置Endpoint地址,可以兼容
func newS3Client() (*s3.Client, error) {
cfg := global.GVA_CONFIG.AwsS3
awsCfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion(cfg.Region),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
cfg.SecretID,
cfg.SecretKey,
"",
)),
)
if err != nil {
logger.Bg().Mod("upload").Err(err).Error("function config.LoadDefaultConfig() failed")
return nil, errors.New("function config.LoadDefaultConfig() failed, err:" + err.Error())
}
return s3.NewFromConfig(awsCfg, func(o *s3.Options) {
if cfg.Endpoint != "" {
endpoint := cfg.Endpoint
if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
if cfg.DisableSSL {
endpoint = "http://" + endpoint
} else {
endpoint = "https://" + endpoint
}
}
o.BaseEndpoint = aws.String(endpoint)
}
o.UsePathStyle = cfg.S3ForcePathStyle
}), nil
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Read the wrapped err text to identify which config source failed (profile file, env var, region)
- Check AWS_PROFILE / AWS_CONFIG_FILE / AWS_SHARED_CREDENTIALS_FILE env vars on the server and unset or fix them
- Confirm AccessKey and SecretKey are set and non-empty in the S3 upload config
- Pin the region explicitly in config so the SDK's region resolution chain cannot fail
- Test credentials with 'aws sts get-caller-identity' using the same env to reproduce outside the app
Example fix
// before (host env) AWS_PROFILE=broken-profile ./server // after unset AWS_PROFILE AWS_CONFIG_FILE ./server # static credentials from config are now the only source
Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("AWS_PROFILE") != "" {
return errors.New("AWS_PROFILE set; would interfere with static S3 credentials")
}
if cfg.AccessKey == "" || cfg.SecretKey == "" || cfg.Bucket == "" {
return errors.New("s3 config incomplete")
} Type guard
null
Try / catch
client, err := newS3Client(cfg)
if err != nil {
logger.Error("s3 client init failed", zap.Error(err))
return fmt.Errorf("s3 client init: %w", err)
} Prevention
- Keep server environments free of AWS_PROFILE/AWS_CONFIG_FILE unless intentionally used
- Provide all four values (access key, secret, region, bucket) via config, not the env credential chain
- Add a startup health check that constructs the S3 client and fails fast
- Pin aws-sdk-go-v2 module versions and review changelogs on upgrades
When it happens
Trigger: Any public method on the AWS S3 uploader (UploadFile, DeleteFile, Exists, DeleteFiles, ListFiles) that lazily constructs the client when cfg values produce an invalid config — e.g. malformed AWS_CONFIG_FILE / shared credentials profile referenced by env, or LoadDefaultConfig options returning an error.
Common situations: AWS_CONFIG_FILE or AWS_SHARED_CREDENTIALS_FILE env var points to a corrupt/missing file, invalid profile name, bad region format, or an SDK config environment (env vars like AWS_PROFILE set in the container) interfering with the statically supplied credentials.
Related errors
- function config.LoadDefaultConfig() failed, err:
- function client.ListObjectsV2() failed, err:
- 未找到 MCP 独立配置文件,请在当前目录、cmd/mcp 目录或通过 -config / GVA_MCP_CONFIG
- 未能自动识别项目根目录,请在 MCP 配置中设置 autocode.root
- go.mod 中未找到 module 定义
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/df3b7d7c5d70ef2b.
Report an issue: GitHub.