Search code examples
goaws-sdkminioaws-sdk-go

Is aws-go-sdk-v2 integrated with local MinIO server?


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).


Solution

  • 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)