Skip to content

Instantly share code, notes, and snippets.

@lucasallan
Forked from dragonfax/main.go
Created February 9, 2017 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasallan/dd2505320f14437d4430b2a69b1d9675 to your computer and use it in GitHub Desktop.
Save lucasallan/dd2505320f14437d4430b2a69b1d9675 to your computer and use it in GitHub Desktop.
example Riak CS (s3 API) client using aws-sdk-go
package main
import (
"bytes"
"fmt"
"io/ioutil"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/s3"
)
func main() {
key := "XXXXX"
secret := "XXXXX"
svc := s3.New(&aws.Config{
Credentials: credentials.NewStaticCredentials(
key,
secret,
""),
Endpoint: aws.String("192.168.45.42:8080"), // Where Riak CS was running (via docker)
Region: aws.String("US"),
S3ForcePathStyle: aws.Bool(true),
DisableSSL: aws.Bool(true),
})
listout, err := svc.ListObjects(&s3.ListObjectsInput{
Bucket: aws.String("test"),
})
if err != nil {
panic(err)
}
fmt.Printf("%v\n", listout)
putout, err := svc.PutObject(&s3.PutObjectInput{
Body: bytes.NewReader([]byte("this is a test")),
Bucket: aws.String("test"),
Key: aws.String("test_file"),
})
if err != nil {
panic(err)
}
fmt.Printf("%v\n", putout)
getout, err := svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String("test"),
Key: aws.String("test_file"),
})
if err != nil {
panic(err)
}
fmt.Printf("%v\n", getout)
buf, err := ioutil.ReadAll(getout.Body)
if err != nil {
panic(err)
}
fmt.Println(string(buf))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment