Go 中的 AWS 开发工具包不从配置文件中获取区域信息

AWS SDK in Go does not take region information from profile

正在努力跟随官方example列出桶

    sess, err := session.NewSessionWithOptions(session.Options{
        Profile: "my-profile",
    })

    if err != nil {
        exitErrorf("Unable to create session, %v", err)
    }

    // Create S3 service client
    svc := s3.New(sess)
    result, err := svc.ListBuckets(nil)
    if err != nil {
        exitErrorf("Unable to list buckets, %v", err)
    }

请注意 my-profile(驻留在 ~/.aws/credentials 中)具有关联的区域信息

[my-profile]
aws_access_key_id=XXXXXXX
aws_secret_access_key=XXXXXXX
region=us-east-1

程序失败如下:

Unable to list buckets, MissingRegion: could not find region configuration
exit status 1

编辑:通过在这行代码前面加上我的方法解决了这个问题

os.Setenv("AWS_REGION", "us-east-1")

但我想正确的方法应该是让 SDK 适当地读取配置文件,不是吗?

region is set~/.aws/config.

~/.aws/config

[my-profile]
region=us-east-1

~/.aws/credentials

[my-profile]
aws_access_key_id=XXXXXXX
aws_secret_access_key=XXXXXXX