Is there an API to read aws s3 file in Go, I only find the API to download file to local machine, and then read the local downloaded file, but I need to read file in stream (like reading a local file).
I want to be able to read the file in real time, like read 100 bytes, do something to the 100 bytes, and read the last file. I only find the Go aws s3 API to download the entire file to local machine, and the handle the downloaded local file.
My current test code is this
func main() {
bucket := "private bucket"
item := "private item"
file, err := os.Create("local path")
if err != nil {
exitErrorf("Unable to open file %q, %v", item, err)
}
defer file.Close()
sess, _ := session.NewSession(&aws.Config{
Region: aws.String(" ")},
)
downloader := s3manager.NewDownloader(sess)
numBytes, err := downloader.Download(file,
&s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(item),
})
// Handle the downloaded file
scanner := bufio.NewScanner(file)
for scanner.Scan() {
// Do something
}
}
I will download the file from s3 to local machine and then open the downloaded file and handle each byte.
I wonder can i directly read each line of the file(or read each 100 bytes of the file) from s3