我试图使用Go (lang)中的S3包将文件字节上传到goamz/s3 AWS。
运行以下代码时:
var (
awsAuth aws.Auth
region aws.Region
connection s3.S3
bucket *s3.Bucket
)
func init() {
// Set up the AWS S3 Connection config.
awsAuth = aws.Auth{
AccessKey: os.Getenv("ACCESS_KEY"), // change this to yours
SecretKey: os.Getenv("SECRET_KEY"),
}
fmt.Println("AWS: ", awsAuth)
region := aws.EUWest
connection := s3.New(awsAuth, region)
bucket = connection.Bucket(os.Getenv("S3_BUCKET")) // change this your bucket name
}
func uploadToS3(filename string, byteArray *[]byte) error {
var err error
//should check if file already uploaded, encrypted by this password
fmt.Printf("[uploadToS3] starting upload of %s\n", filename)
err = bucket.Put(filename, *byteArray, "text/plain; charset=utf-8", s3.PublicRead)
if err != nil {
fmt.Printf("[uploadToS3] error uploading: %s\n", err)
return err
} else {
fmt.Printf("[uploadToS3] done uploading %s\n", filename)
return nil
}
return nil // redundancy
}我知道错误了
[uploadToS3] error uploading: Put /filename: unsupported protocol scheme ""
从创建ec2安全组时不支持的协议方案来看,原因似乎是一个不正确的区域,但事实并非如此,因为它是在init()中设置的。
任何想法都将不胜感激。
发布于 2017-01-03 11:29:06
任何可能有同样问题的人。如果未设置桶名,则会出现错误。看起来很蠢,但我在码头里运行了这个,忘了告诉对接者环境变量是什么,它保留了桶名。因此,当我在我的终端上做echo $S3_BUCKET时,我得到了桶名,因此我认为一切都很好。不过,我并没有在码头集装箱里测试这个。愚弄我。
发布于 2022-11-11 15:51:17
在设置AWS配置以允许我指定AWS端点时,V2遇到了这个问题(在集成测试期间,我将服务指向本地堆栈)。
我通过使用自定义端点解析器来解析它。
conf, err := config.LoadDefaultConfig(
ctx,
config.WithRegion(region),
config.WithRetryMaxAttempts(3),
config.WithEndpointResolver(aws.EndpointResolverFunc(func(_, region string) (aws.Endpoint, error) {
if internal.AwsEndpoint != "" {
return aws.Endpoint{
PartitionID: "aws",
URL: internal.AwsEndpoint,
SigningRegion: region,
}, nil
}
// returning EndpointNotFoundError will allow the service to fallback to it's default resolution
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
})),
)
...
client := s3.NewFromConfig(conf, func(o *s3.Options) {
o.UsePathStyle = true
})https://stackoverflow.com/questions/41434410
复制相似问题