Skip to content

Instantly share code, notes, and snippets.

@krishnasrinivas
Created November 28, 2017 21:59
Show Gist options
  • Save krishnasrinivas/23ed37f564d18b624da9436b7714e3c1 to your computer and use it in GitHub Desktop.
Save krishnasrinivas/23ed37f564d18b624da9436b7714e3c1 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
)
func main() {
bucket := aws.String("test")
key := aws.String("passwd")
// Configure to use Minio Server
s3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials("SXO8VW2OFKKP2OG7AC85", "CKWSSgrUgvfUMTaNBkB63exet4WW+uNhQvi91Bc3", ""),
Endpoint: aws.String("http://localhost:9000"),
Region: aws.String("us-east-1"),
DisableSSL: aws.Bool(true),
S3ForcePathStyle: aws.Bool(true),
}
newSession := session.New(s3Config)
file, err := os.Create("testobject_local")
if err != nil {
fmt.Println("Failed to create file", err)
return
}
defer file.Close()
downloader := s3manager.NewDownloader(newSession)
numBytes, err := downloader.Download(file,
&s3.GetObjectInput{
Bucket: bucket,
Key: key,
})
if err != nil {
fmt.Println("Failed to download file", err)
return
}
fmt.Println("Downloaded file", file.Name(), numBytes, "bytes")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment