Examples

AWS SDK for Go

Connect the AWS SDK for Go v2 to RustFS and perform basic object operations.

The AWS SDK for Go v2 connects to RustFS through a custom base endpoint. This is the minimal connection recipe; see the Go SDK guide for a full program.

Install

go get github.com/aws/aws-sdk-go-v2/aws
go get github.com/aws/aws-sdk-go-v2/credentials
go get github.com/aws/aws-sdk-go-v2/service/s3

Configure

Replace http://localhost:9000 with your server address and use your own access keys. RustFS requires path-style addressing (UsePathStyle: true):

import (
    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/credentials"
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

cfg := aws.Config{
    Region:      "us-east-1",
    Credentials: aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider("<your-access-key>", "<your-secret-key>", "")),
}
client := s3.NewFromConfig(cfg, func(o *s3.Options) {
    o.BaseEndpoint = aws.String("http://localhost:9000")
    o.UsePathStyle = true
})

Verify

ctx := context.Background()
client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: aws.String("my-bucket")})

out, _ := client.ListBuckets(ctx, &s3.ListBucketsInput{})
for _, b := range out.Buckets {
    fmt.Println(*b.Name)
}
my-bucket

Next steps

See the full Go SDK guide, or manage objects with mc.

On this page