Go SDK¶
We will show you how to use Tebi with the AWS Go SDK v2 by Amazon in your own projects.
Installation¶
Make sure to add the required libraries to your go project (go.mod):
require (
github.com/aws/aws-sdk-go-v2 v1.16.8
github.com/aws/aws-sdk-go-v2/config v1.15.15
github.com/aws/aws-sdk-go-v2/credentials v1.12.10
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.2
)
Using the SDK¶
It is important to add a custom endpoint resolver and a custom configuration with your keys.
1customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
2 return aws.Endpoint{
3 PartitionID: "aws",
4 URL: "https://s3.tebi.io",
5 SigningRegion: "de",
6 }, nil
7 })
8
9 customConfig := config.LoadOptionsFunc(func(configOptions *config.LoadOptions) error {
10 configOptions.Credentials = credentials.StaticCredentialsProvider{Value: aws.Credentials{AccessKeyID: "YOUR_ACCESS_KEY", SecretAccessKey: "YOUR_SECRET_KEY"}}
11 return nil
12 })
Following up, we create a config instance that can be used by the SDK:
1 cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithEndpointResolverWithOptions(customResolver), customConfig)
2 if err != nil {
3 log.Fatalf("unable to load SDK config, %v", err)
4 }
Now we create the object…
1svc := s3.NewFromConfig(cfg)
…and we are ready to go. For example, listing the available buckets:
1 resp, err := svc.ListBuckets(context.TODO(), &s3.ListBucketsInput{})
2 if err != nil {
3 log.Fatalf("unable to fetch buckets --> %v", err)
4 }
5
6 fmt.Println("Buckets: ")
7 for _, bucketEntry := range resp.Buckets {
8 fmt.Printf("resp.Buckets entry -> %+v", bucketEntry)
9 fmt.Printf(" - real name: %v\n", aws.ToString(bucketEntry.Name))
10 }
For more available functions, please refer to the documentation of the aws-sdk-go-v2 library, which you can find at go.pkg.dev.