minio/minio-go

ListObjects on an empty bucket is failing with key doesn't exist

panbanda opened this issue · 1 comments

I discovered this when trying to set up Tempo on a new S3 bucket and minio was failing at this function as soon as I switched the storage to S3. Tempo does a confirm on boot to see if the bucket contents are accessible, but this test fails because of the following example code even though the bucket is accessible and has all the necessary permissions.

Expected Behavior

.ListObjects should return a list of objects, or empty

Current Behavior

.ListObjects returns an error on an empty bucket The specified key does not exist.

Steps to Reproduce (for bugs)

To reproduce you can use this small go program and an empty s3 bucket

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
)

func main() {
	endpoint := "bucket.s3.us-east-2.amazonaws.com"
	accessKeyID := "AAAA"
	secretAccessKey := "AAAA"
	useSSL := true
	bucket := "bucket"

	ctx := context.Background()
	minioClient, err := minio.New(endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
		Secure: useSSL,
	})
	if err != nil {
		log.Fatalln(err)
	}

	opts := minio.ListObjectsOptions{}

	for object := range minioClient.ListObjects(ctx, bucket, opts) {
		if object.Err != nil {
			fmt.Println(object.Err)
		} else {
			fmt.Println(object.Key)
		}
	}
}

The output is:

go run main.go
The specified key does not exist.

Your endpoint must s3.us-east-2.amazonaws.com without the bucketname