func LatestLogFilesList(client *s3.S3, downloader *s3manager.Downloader, numLogs int) ([]string, error) { params := &s3.ListObjectsInput{ Bucket: aws.String("lattice-logs"), MaxKeys: aws.Int64(1<<31 - 1), Prefix: aws.String("logs/"), } logFiles := []string{} err := client.ListObjectsPages(params, func(page *s3.ListObjectsOutput, lastPage bool) bool { for _, o := range page.Contents { logFiles = append(logFiles, *o.Key) } return true }) if err != nil { return []string{}, err } return logFiles[len(logFiles)-numLogs-1 : len(logFiles)-1], nil }
// ListS3Objects returns all object keys matching the given prefix. Note that // delimiter is set to "/". See http://docs.aws.amazon.com/AmazonS3/latest/dev/ListingKeysHierarchy.html func ListS3Objects(client *s3.S3, bucket, keyPrefix string) ([]string, error) { logger.Debug("ListS3Objects: ", bucket, "-", keyPrefix) params := &s3.ListObjectsInput{ Bucket: aws.String(bucket), // Required Delimiter: aws.String("/"), // EncodingType: aws.String("EncodingType"), // Marker: aws.String("Marker"), MaxKeys: aws.Int64(1000), Prefix: aws.String(keyPrefix), } objects := []string{} err := client.ListObjectsPages(params, func(page *s3.ListObjectsOutput, lastPage bool) bool { for _, o := range page.Contents { objects = append(objects, *o.Key) } return lastPage }) if err != nil { return nil, err } return objects, nil }