CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/golang-github-com--aws--aws-sdk-go-v2

AWS SDK for Go v2 with 130+ service clients, Request/Send pattern, and context support.

Overview
Eval results
Files

utilities.mddocs/reference/

SDK Utilities

ARN Parsing (aws/arn)

Import: github.com/aws/aws-sdk-go-v2/aws/arn

type ARN struct {
    // "aws", "aws-cn", or "aws-us-gov"
    Partition string

    // Service namespace (e.g., "s3", "iam", "ec2")
    Service string

    // AWS region (empty for global services like IAM)
    Region string

    // AWS account ID without hyphens (empty for some resources)
    AccountID string

    // Resource type and name (format varies by service)
    // Examples: "bucket-name", "user/username", "db:mysql-db"
    Resource string
}

func Parse(arn string) (ARN, error)
func (arn ARN) String() string
// Parse an ARN
arnStr := "arn:aws:s3:::my-bucket"
parsed, err := arn.Parse(arnStr)
if err != nil { ... }
fmt.Println(parsed.Service)   // "s3"
fmt.Println(parsed.Resource)  // "my-bucket"

// Examples of valid ARN formats:
// arn:aws:elasticbeanstalk:us-east-1:123456789012:environment/MyApp/MyEnv
// arn:aws:iam::123456789012:user/David
// arn:aws:rds:eu-west-1:123456789012:db:mysql-db
// arn:aws:s3:::my_corporate_bucket/exampleobject.png

Default Handlers (aws/defaults)

Import: github.com/aws/aws-sdk-go-v2/aws/defaults

Pre-built request handlers and default configuration. Generally used internally; prefer external.LoadDefaultAWSConfig() for setup.

// Pre-built named handlers
var SDKVersionUserAgentHandler aws.NamedHandler    // adds SDK version to User-Agent
var AddHostExecEnvUserAgentHander aws.NamedHandler // adds AWS_EXECUTION_ENV to User-Agent
var SendHandler aws.NamedHandler                   // executes HTTP send
var ValidateEndpointHandler aws.NamedHandler       // validates region/endpoint are set
var ValidateParametersHandler aws.NamedHandler     // validates request parameters
var ValidateReqSigHandler aws.NamedHandler         // validates request signature configuration
var ValidateResponseHandler aws.NamedHandler       // validates HTTP response
var BuildContentLengthHandler aws.NamedHandler     // builds Content-Length header
var AfterRetryHandler aws.NamedHandler             // handles retry logic

// Get the default handler chain
func Handlers() aws.Handlers

// Get default aws.Config with SDK defaults applied
func Config() aws.Config

// Get the default HTTP client
func HTTPClient() *http.Client

// Get the default logger
func Logger() aws.Logger

// Get the default credential chain provider
func CredChain(cfg aws.Config, handlers aws.Handlers) aws.CredentialsProvider

The default credential chain tries:

  1. Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  2. Shared credentials file (~/.aws/credentials)
  3. Shared config file (~/.aws/config)
  4. ECS container credentials (if AWS_CONTAINER_CREDENTIALS_RELATIVE_URI or AWS_CONTAINER_CREDENTIALS_FULL_URI is set)
  5. EC2 instance role credentials

WriteAtBuffer (aws)

In-memory buffer implementing io.WriterAt. Use with s3manager.Downloader to download to memory.

// From github.com/aws/aws-sdk-go-v2/aws
type WriteAtBuffer struct {
    GrowthCoeff float64  // buffer growth multiplier (default: 1.0)
    // unexported fields
}

func NewWriteAtBuffer(buf []byte) *WriteAtBuffer
func (b *WriteAtBuffer) Bytes() []byte
func (b *WriteAtBuffer) WriteAt(p []byte, pos int64) (n int, err error)
// Download S3 object to memory
downloader := s3manager.NewDownloader(cfg)
buf := aws.NewWriteAtBuffer([]byte{})
n, err := downloader.Download(buf, &s3.GetObjectInput{
    Bucket: aws.String("my-bucket"),
    Key:    aws.String("small-file.json"),
})
data := buf.Bytes() // the downloaded content

Context Utilities (aws)

// From github.com/aws/aws-sdk-go-v2/aws
type Context = context.Context

// Returns context.Background() - use when no context is available
func BackgroundContext() Context

// Sleep for duration or until context is canceled
func SleepWithContext(ctx Context, dur time.Duration) error

Logging Utilities (aws)

// From github.com/aws/aws-sdk-go-v2/aws
type LogLevel uint

const (
    LogOff   LogLevel = iota * 0x1000  // no logging (default)
    LogDebug                            // log request/response details
)

// Debug sub-levels (combine with LogDebug)
const (
    LogDebugWithSigning      LogLevel = LogDebug | (1 << iota)
    LogDebugWithHTTPBody
    LogDebugWithRequestRetries
    LogDebugWithRequestErrors
)

func (l LogLevel) Matches(v LogLevel) bool
func (l LogLevel) AtLeast(v LogLevel) bool

type Logger interface {
    Log(...interface{})
}

type LoggerFunc func(...interface{})
func (f LoggerFunc) Log(args ...interface{})

func NewDefaultLogger() Logger
// Enable debug logging with HTTP body
cfg.LogLevel = aws.LogDebugWithHTTPBody
cfg.Logger = aws.NewDefaultLogger()

// Custom logger
cfg.Logger = aws.LoggerFunc(func(args ...interface{}) {
    log.Println(args...)
})

Install with Tessl CLI

npx tessl i tessl/golang-github-com--aws--aws-sdk-go-v2

docs

index.md

tile.json