> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tensor9.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS Go SDK Guide

> Configure AWS SDK for Go v2 to use a Cloud Adapter endpoint with bounded request behavior.

This guide uses AWS SDK for Go v2 and S3. The application keeps using AWS request and response types; only the client endpoint changes.

## Choose how to set the endpoint

### Set it for the process

```bash theme={null}
export AWS_ENDPOINT_URL_S3="https://adapter.example.test"
```

AWS SDK for Go v2 reads that service-specific setting during `LoadDefaultConfig`. Build the S3 client without assigning `BaseEndpoint`:

```go theme={null}
import (
    "context"

    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

func newS3(ctx context.Context) (*s3.Client, error) {
    cfg, err := config.LoadDefaultConfig(ctx,
        config.WithRegion("us-east-1"),
        config.WithSharedConfigProfile("adapter-test"),
    )
    if err != nil { return nil, err }

    client := s3.NewFromConfig(cfg, func(options *s3.Options) {
        options.UsePathStyle = true
    })
    return client, nil
}
```

### Set it on one client

```bash theme={null}
export T9_CLOUD_ADAPTER_ENDPOINT="https://adapter.example.test"
```

```go theme={null}
package main

import (
    "context"
    "io"
    "os"
    "strings"
    "time"

    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

func newS3(ctx context.Context) (*s3.Client, error) {
    cfg, err := config.LoadDefaultConfig(ctx,
        config.WithRegion("us-east-1"),
        config.WithSharedConfigProfile("adapter-test"),
    )
    if err != nil {
        return nil, err
    }

    endpoint := os.Getenv("T9_CLOUD_ADAPTER_ENDPOINT")
    return s3.NewFromConfig(cfg, func(options *s3.Options) {
        options.BaseEndpoint = aws.String(endpoint)
        options.UsePathStyle = true
    }), nil
}
```

Keep the endpoint in a client factory. Do not install a process-wide resolver that redirects unrelated AWS services unless every redirected service has a configured adapter.

`BaseEndpoint` on the client takes precedence over `AWS_ENDPOINT_URL_S3`.

## Verify an object lifecycle

```go theme={null}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

client, err := newS3(ctx)
if err != nil { panic(err) }

bucket := os.Getenv("TEST_BUCKET")
key := "go/" + time.Now().UTC().Format("20060102T150405.000000000Z") + "-hello.txt"
body := "hello through Cloud Adapter\n"

_, err = client.PutObject(ctx, &s3.PutObjectInput{
    Bucket: aws.String(bucket),
    Key: aws.String(key),
    Body: strings.NewReader(body),
    ContentType: aws.String("text/plain"),
})
if err != nil { panic(err) }

_, err = client.HeadObject(ctx, &s3.HeadObjectInput{Bucket: aws.String(bucket), Key: aws.String(key)})
if err != nil { panic(err) }

got, err := client.GetObject(ctx, &s3.GetObjectInput{Bucket: aws.String(bucket), Key: aws.String(key)})
if err != nil { panic(err) }
defer got.Body.Close()

actual, err := io.ReadAll(got.Body)
if err != nil { panic(err) }
if string(actual) != body { panic("downloaded bytes differ") }

_, err = client.DeleteObject(ctx, &s3.DeleteObjectInput{Bucket: aws.String(bucket), Key: aws.String(key)})
if err != nil { panic(err) }
```

In production, do not read unbounded object bodies into memory.

## Classify failures before retrying

Use `errors.As` to distinguish a service response from a transport or context failure. Capture the Smithy operation error, service error code, HTTP status, and request ID when present. A context deadline after `PutObject` is an uncertain write; inspect target state before retrying.

## Production checklist

* Pin the Go v2 module versions you test.
* Give every request an appropriate deadline.
* Reuse clients and HTTP transports.
* Test paginator termination and continuation tokens.
* Verify path-style or virtual-host addressing for the deployed endpoint.
* Compare native target state after writes.
* Exercise one expected not-found response.

See the [S3 service page](/cloud-adapter/service-catalog/aws/databases-storage/s3), [response headers](/cloud-adapter/debugging/response-headers), and [testing guide](/cloud-adapter/local-testing/testing-your-adapters).
