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

errors.mddocs/reference/

Error Handling (aws/awserr)

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

The SDK uses typed errors that implement the awserr.Error interface, providing structured access to AWS API error codes, messages, and HTTP status information.

Error Interface

type Error interface {
    // Satisfy stdlib error interface
    error

    // Short code classifying the error (e.g., "NoSuchBucket", "AccessDenied")
    Code() string

    // Human-readable error details
    Message() string

    // Original underlying error (e.g., network error), or nil
    OrigErr() error
}

func New(code, message string, origErr error) Error

RequestFailure Interface

For errors from AWS service calls that have HTTP context.

type RequestFailure interface {
    Error  // embeds Error interface

    // HTTP response status code (e.g., 404, 500)
    StatusCode() int

    // AWS request ID for tracing (empty if request failed before reaching AWS)
    RequestID() string
}

func NewRequestFailure(err Error, statusCode int, reqID string) RequestFailure

BatchedErrors Interface

For operations that return multiple errors.

type BatchedErrors interface {
    Error  // embeds Error interface

    // All original errors in the batch
    OrigErrs() []error
}

func NewBatchError(code, message string, errs []error) BatchedErrors

// Deprecated: use BatchedErrors
type BatchError interface { ... }

Error Formatting

func SprintError(code, message, extra string, origErr error) string

Common Error Handling Pattern

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

resp, err := svc.GetObjectRequest(&s3.GetObjectInput{
    Bucket: aws.String("my-bucket"),
    Key:    aws.String("my-key"),
}).Send()

if err != nil {
    // Check if it's an AWS error
    if aerr, ok := err.(awserr.Error); ok {
        fmt.Println("Code:", aerr.Code())
        fmt.Println("Message:", aerr.Message())

        // Check for original error
        if origErr := aerr.OrigErr(); origErr != nil {
            fmt.Println("Caused by:", origErr)
        }

        // Check for HTTP error with request ID
        if reqErr, ok := err.(awserr.RequestFailure); ok {
            fmt.Println("HTTP Status:", reqErr.StatusCode())
            fmt.Println("Request ID:", reqErr.RequestID())
        }

        // Match specific error codes
        switch aerr.Code() {
        case s3.ErrCodeNoSuchKey:
            fmt.Println("Object not found")
        case s3.ErrCodeNoSuchBucket:
            fmt.Println("Bucket not found")
        case "AccessDenied":
            fmt.Println("Access denied")
        case "NoCredentialProviders":
            fmt.Println("No AWS credentials configured")
        }
    } else {
        // Non-AWS error (network, timeout, etc.)
        fmt.Println("Error:", err)
    }
}

SDK Error Code Constants (aws package)

// From github.com/aws/aws-sdk-go-v2/aws
const (
    ErrCodeSerialization   = "SerializationError"
    ErrCodeRead            = "ReadError"
    ErrCodeResponseTimeout = "ResponseTimeout"
    ErrCodeRequestCanceled = "RequestCanceled"

    InvalidParameterErrCode = "InvalidParameter"
    ParamRequiredErrCode    = "ParamRequiredError"
    ParamMinValueErrCode    = "ParamMinValueError"
    ParamMinLenErrCode      = "ParamMinLenError"

    WaiterResourceNotReadyErrorCode = "ResourceNotReady"
)

var (
    ErrMissingRegion   error // "MissingRegion"
    ErrMissingEndpoint error // "MissingEndpoint"
)

Service-Specific Error Codes

Each service package defines error code constants for its common errors.

S3 Error Codes

// From github.com/aws/aws-sdk-go-v2/service/s3
const (
    ErrCodeBucketAlreadyExists                    = "BucketAlreadyExists"
    ErrCodeBucketAlreadyOwnedByYou                = "BucketAlreadyOwnedByYou"
    ErrCodeNoSuchBucket                           = "NoSuchBucket"
    ErrCodeNoSuchKey                              = "NoSuchKey"
    ErrCodeNoSuchUpload                           = "NoSuchUpload"
    ErrCodeObjectAlreadyInActiveTierError         = "ObjectAlreadyInActiveTierError"
    ErrCodeObjectNotInActiveTierError             = "ObjectNotInActiveTierError"
)

DynamoDB Error Codes

// From github.com/aws/aws-sdk-go-v2/service/dynamodb
const (
    ErrCodeBackupInUseException                   = "BackupInUseException"
    ErrCodeBackupNotFoundException                = "BackupNotFoundException"
    ErrCodeConditionalCheckFailedException        = "ConditionalCheckFailedException"
    ErrCodeGlobalTableAlreadyExistsException      = "GlobalTableAlreadyExistsException"
    ErrCodeGlobalTableNotFoundException           = "GlobalTableNotFoundException"
    ErrCodeIndexNotFoundException                 = "IndexNotFoundException"
    ErrCodeInternalServerError                    = "InternalServerError"
    ErrCodeItemCollectionSizeLimitExceededException = "ItemCollectionSizeLimitExceededException"
    ErrCodeLimitExceededException                 = "LimitExceededException"
    ErrCodePointInTimeRecoveryUnavailableException = "PointInTimeRecoveryUnavailableException"
    ErrCodeProvisionedThroughputExceededException = "ProvisionedThroughputExceededException"
    ErrCodeReplicaAlreadyExistsException          = "ReplicaAlreadyExistsException"
    ErrCodeReplicaNotFoundException               = "ReplicaNotFoundException"
    ErrCodeResourceInUseException                 = "ResourceInUseException"
    ErrCodeResourceNotFoundException              = "ResourceNotFoundException"
    ErrCodeTableAlreadyExistsException            = "TableAlreadyExistsException"
    ErrCodeTableInUseException                    = "TableInUseException"
    ErrCodeTableNotFoundException                 = "TableNotFoundException"
)

Error Checking Utilities (aws package)

// From github.com/aws/aws-sdk-go-v2/aws
func IsErrorExpiredCreds(err error) bool  // true if credentials expired
func IsErrorRetryable(err error) bool     // true if error is retryable
func IsErrorThrottle(err error) bool      // true if request was throttled

These check the error code against known retryable/throttle codes, making it easier to implement retry logic.

Credential Errors

var ErrStaticCredentialsEmpty = awserr.New("EmptyStaticCreds", "static credentials are empty", nil)

ARN Parsing Errors

aws/arn.Parse() returns a plain error (not awserr.Error) when the ARN string is malformed.

Install with Tessl CLI

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

docs

index.md

tile.json