Skip to content
davidlin2kPublic

About

Go bindings for AWS Common Runtime (CRT) S3

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

s3crt-go

Go bindings for AWS Common Runtime (CRT) S3, enabling high-throughput S3 transfers via the same C library stack used by AWS CLI v2.

CRT improves throughput through automatic multipart splitting, parallel connections, DNS load balancing, and per-chunk retries. See the AWS blog post for benchmarks and details.

Status: Early development. The API is not yet stable.

Quick Start

package main

import (
    "context"
    "log"
    "os"

    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/davidlin2k/s3crt-go"
)

func main() {
    ctx := context.Background()
    awsCfg, err := config.LoadDefaultConfig(ctx)
    if err != nil {
        log.Fatal(err)
    }

    client, err := s3crt.NewClient(awsCfg)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    f, err := os.Create("large-file.bin")
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()

    _, err = client.Download(ctx, f, &s3crt.DownloadInput{
        Bucket: "my-bucket",
        Key:    "large-file.bin",
    })
    if err != nil {
        log.Fatal(err)
    }
}

Prerequisites

  • Go 1.24+
  • C compiler (gcc or clang)
  • CMake 3.9+
  • Make

Building

git clone --recursive https://github.com/davidlin2k/s3crt-go.git
cd s3crt-go
make deps   # Build CRT C libraries (~2 min first time)
make build  # Build Go code
make test   # Run tests

The CRT C libraries are vendored as git submodules under crt/ and statically linked. No system-level CRT installation is needed.

API

Client

client, err := s3crt.NewClient(awsCfg, opts...)
defer client.Close()

Credentials and region are taken from the aws.Config passed to NewClient.

Transfer Operations

// Download to io.Writer
output, err := client.Download(ctx, writer, &s3crt.DownloadInput{...})

// Download as streaming io.ReadCloser
reader, output, err := client.DownloadReader(ctx, &s3crt.DownloadInput{...})

// Upload from io.Reader
output, err := client.Upload(ctx, reader, &s3crt.UploadInput{...})

// Upload directly from file (avoids copying through Go)
output, err := client.UploadFile(ctx, "/path/to/file", &s3crt.UploadInput{...})

// Server-side copy
output, err := client.Copy(ctx, &s3crt.CopyInput{...})

Metadata Operations

output, err := client.HeadObject(ctx, &s3crt.HeadObjectInput{...})
output, err := client.DeleteObject(ctx, &s3crt.DeleteObjectInput{...})
output, err := client.DeleteObjects(ctx, &s3crt.DeleteObjectsInput{...})

// Paginated listing
it := client.ListObjectsV2(ctx, &s3crt.ListObjectsV2Input{Bucket: "my-bucket"})
for it.Next() {
    obj := it.Object()
    fmt.Println(obj.Key, obj.Size)
}
if err := it.Err(); err != nil { ... }

Configuration

s3crt.WithThroughputTarget(10.0)     // Gbps (default: 10.0)
s3crt.WithPartSize(16 * 1024 * 1024) // bytes (default: 8 MiB)
s3crt.WithMaxConnections(100)        // 0 = auto from throughput target
s3crt.WithMemoryLimit(2 << 30)       // bytes, 0 = unlimited
s3crt.WithReadBackpressure(8 << 20)  // enable download flow control

Per-Transfer Options

s3crt.WithProgress(func(p s3crt.TransferProgress) { ... })
s3crt.WithPartSizeOverride(32 << 20)
s3crt.WithChecksum(s3crt.ChecksumCRC32C, s3crt.ChecksumLocationTrailer)
s3crt.WithChecksumValidation()

Architecture

s3crt (Go API)  -->  internal/crt (CGo)  -->  aws-c-s3 (C)

The public s3crt package exposes idiomatic Go types (io.Reader, context.Context, aws.Config). All CGo and C types are isolated in internal/crt. The CRT C libraries are built as static archives and linked into the Go binary.

Platform Support

  • Linux (tested)
  • macOS (should work; uses Security.framework for TLS instead of s2n)
  • Windows is not supported

License

Apache 2.0

About

Go bindings for AWS Common Runtime (CRT) S3

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages