I am trying to use Golang to list all the objects in S3 Bucket, however, I found the Golang
S3 List function would return only 1000 objects.
So, in PHP, I can use
$objects=S3->getIterator('ListObjects', array('Bucket' => $bucket,'Prefix'=>'test/'));
which can return the next 100x objects if I iterate the 100X items in $objects. So is there any
mechanism (or iterator function) in Golang that I can also iterate the next 1000 objects from
the iterator?
Thanks
Edit: Yes, they do.
var (
sqsRegion string
)
func init() {
if err := godotenv.Load(); err != nil {
log.Fatalf("Error loading .env file: %s", err.Error())
}
sqsRegion = os.Getenv("AWS_REGION")
}
func main() {
sess := session.New(&aws.Config{Region: aws.String(sqsRegion)})
svc := s3.New(sess)
resp, err := svc.ListObjects(&s3.ListObjectsInput{
Bucket: aws.String("yourbucket"),
})
if err != nil {
log.Fatalln(err.Error())
}
for _, key := range resp.Contents {
log.Println(*key.Key)
}
}