How can I hook up my local minIO storage with aws-sdk-go-v2
? I can find clear documentation of how to do that in the previous version of go SDK but not with V2. I read through the version 2 source code and it seems aws-sdk-go-v2
removed the option to disable SSL and specify a local S3 endpoint(the service URL has to be in amazon style).
Asked
Active
Viewed 2,352 times
5

Susie
- 103
- 6
3 Answers
11
You can do this easily enough with:
const defaultRegion = "us-east-1"
staticResolver := aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
return aws.Endpoint{
PartitionID: "aws",
URL: "http://localhost:9123", // or where ever you ran minio
SigningRegion: defaultRegion,
HostnameImmutable: true,
}, nil
})
cfg = aws.Config{
Region: defaultRegion,
Credentials: credentials.NewStaticCredentialsProvider("minioadmin", "minioadmin", ""),
EndpointResolver: staticResolver,
}
s3Client := s3.NewFromConfig(cfg)

danmux
- 2,735
- 1
- 25
- 28
-
1Thank you danmux. Your solution worked for me. Thank you! – Susie Jun 24 '21 at 01:27
3
As of today aws.EndpointResolverFunc is deprecated this is what worked for me:
const defaultRegion = "us-east-1"
hostAddress := "http://localhost:9000"
resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) {
return aws.Endpoint{
PartitionID: "aws",
URL: hostAddress,
SigningRegion: defaultRegion,
HostnameImmutable: true,
}, nil
})
cfg, err = config.LoadDefaultConfig(context.Background(),
config.WithRegion(defaultRegion),
config.WithEndpointResolverWithOptions(resolver),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("minioadmin", "minioadmin", "")),
)
s3Client := s3.NewFromConfig(cfg)

Emanuele Fumagalli
- 1,476
- 2
- 19
- 31
1
A derived version for aws-sdk-go-v2
const defaultRegion = "us-east-1"
hostAddress := "http://localhost:9000"
resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) {
return aws.Endpoint{
PartitionID: "aws",
SigningRegion: defaultRegion,
URL: hostAddress,
HostnameImmutable: true,
}, nil
})
cfg := aws.Config{
Region: defaultRegion,
EndpointResolverWithOptions: resolver
Credentials: credentials.NewStaticCredentialsProvider("minioadmin", "minioadmin", ""),
}
return s3.NewFromConfig(cfg)

oscarz
- 1,184
- 11
- 19