How do I use AWS SDK for Go (Golang) with Wasabi?

AWS SDK for Go (Golang) is validated for use with Wasabi.  To use this SDK with Wasabi, please follow the example below.

Note that this example discusses the use of Wasabi's us-east-1 storage region. To use other Wasabi storage regions, please use the appropriate Wasabi service URL as described in this article

package main

import (
"fmt"
"strings"

"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"
)

func main() {
bucket := aws.String("wasabi-golang-example")
key := aws.String("wasabi-testobject")

s3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials("<Wasabi-Access-Key>", "<Wasabi-Secret-key>", ""),
Endpoint: aws.String("https://s3.wasabisys.com"),
Region: aws.String("us-east-1"),
S3ForcePathStyle: aws.Bool(true),
}
newSession := session.New(s3Config)

s3Client := s3.New(newSession)

cparams := &s3.CreateBucketInput{
Bucket: bucket, // Required
}
_, err := s3Client.CreateBucket(cparams)
if err != nil {
// Print if any error.
fmt.Println(err.Error())
return
}
fmt.Printf("Successfully created bucket %s\n", *bucket)

// Upload a new object "wasabi-testobject" with the string "Wasabi Hot storage"
_, err = s3Client.PutObject(&s3.PutObjectInput{
Body: strings.NewReader("wasabi hot storage"),
Bucket: bucket,
Key: key,
})
if err != nil {
fmt.Printf("Failed to upload object %s/%s, %s\n", *bucket, *key, err.Error())
return
}
fmt.Printf("Successfully uploaded key %s\n",*key)

//Get Object
_, err = s3Client.GetObject(&s3.GetObjectInput{
Bucket: bucket,
Key: key,
})
if err != nil {
fmt.Println("Failed to download file", err)
return
}
fmt.Printf("Successfully Downloaded key %s\n",*key)

 

When you use this SDK example with Wasabi, the output from the CLI is this:

$ go run example.go

Successfully created bucket wasabi-golang-example

Successfully uploaded key wasabi-testobject

Successfully Downloaded key wasabi-testobject

Have more questions? Submit a request