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

index.mddocs/

AWS SDK for Go v2

Official AWS SDK for Go v2 (Developer Preview v0.4.0) with 130+ service clients. Features Request/Send pattern, context support, typed requests, and improved configuration.

Installation

dep ensure -add github.com/aws/aws-sdk-go-v2
# or: go get github.com/aws/aws-sdk-go-v2

Quick Start

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

// 1. Load config (from env/files/IAM)
cfg, _ := external.LoadDefaultAWSConfig()
cfg.Region = "us-east-1"

// 2. Create service client
svc := s3.New(cfg)

// 3. Create typed request
req := svc.ListBucketsRequest(&s3.ListBucketsInput{})

// 4. Send request
resp, _ := req.Send()
for _, b := range resp.Buckets {
    fmt.Println(*b.Name)
}

Complete Quick Start →

Core SDK Components

ComponentPurposeReference
awsConfig, helpers, request infrastructureCore →
aws/externalLoad config from env/files/IAMConfig →
aws/awserrAWS error codes and handlingErrors →
aws/endpointsRegion/endpoint resolutionEndpoints →
aws/signer/v4SigV4 request signingSigning →
service/*130+ AWS service clientsServices →

Key APIs

Configuration Loading

// Package: aws/external
func LoadDefaultAWSConfig(configs ...Config) (aws.Config, error)
func WithSharedConfigProfile(profile string) Config
func WithRegion(region string) Config
func WithCredentialsProvider(provider aws.CredentialsProvider) Config
func WithMFATokenFunc(func() (string, error)) Config
func WithAssumeRoleCredentialOptions(func(*stscreds.AssumeRoleProvider)) Config

Service Client Pattern

// All 130+ services follow this pattern:
func New(config aws.Config) *<ServiceName>

// Examples:
func s3.New(config aws.Config) *S3
func dynamodb.New(config aws.Config) *DynamoDB
func ec2.New(config aws.Config) *EC2
func lambda.New(config aws.Config) *Lambda
func sqs.New(config aws.Config) *SQS
func sns.New(config aws.Config) *SNS

Request/Send Pattern

// All operations return typed requests:
func (c *Client) <Operation>Request(input *<Operation>Input) <Operation>Request

// Request methods:
func (r <Operation>Request) Send() (*<Operation>Output, error)
func (r <Operation>Request) Presign(expireTime time.Duration) (string, error)
func (r <Operation>Request) Paginate() <Operation>Paginator
func (r <Operation>Request) SetContext(ctx aws.Context)

Pointer Helpers

// Package: aws
// Create pointers:
func String(v string) *string
func Int64(v int64) *int64
func Int(v int) *int
func Bool(v bool) *bool
func Float64(v float64) *float64
func Time(v time.Time) *time.Time

// Dereference safely (returns zero value if nil):
func StringValue(v *string) string
func Int64Value(v *int64) int64
func IntValue(v *int) int
func BoolValue(v *bool) bool
func Float64Value(v *float64) float64
func TimeValue(v *time.Time) time.Time

Common Services Quick Reference

S3 (Object Storage)

func (c *S3) GetObjectRequest(input *GetObjectInput) GetObjectRequest
func (c *S3) PutObjectRequest(input *PutObjectInput) PutObjectRequest
func (c *S3) DeleteObjectRequest(input *DeleteObjectInput) DeleteObjectRequest
func (c *S3) DeleteObjectsRequest(input *DeleteObjectsInput) DeleteObjectsRequest
func (c *S3) CopyObjectRequest(input *CopyObjectInput) CopyObjectRequest
func (c *S3) HeadObjectRequest(input *HeadObjectInput) HeadObjectRequest
func (c *S3) ListObjectsV2Request(input *ListObjectsV2Input) ListObjectsV2Request
func (c *S3) ListObjectVersionsRequest(input *ListObjectVersionsInput) ListObjectVersionsRequest

S3 Complete API →

DynamoDB (NoSQL)

func (c *DynamoDB) GetItemRequest(input *GetItemInput) GetItemRequest
func (c *DynamoDB) PutItemRequest(input *PutItemInput) PutItemRequest
func (c *DynamoDB) UpdateItemRequest(input *UpdateItemInput) UpdateItemRequest
func (c *DynamoDB) DeleteItemRequest(input *DeleteItemInput) DeleteItemRequest
func (c *DynamoDB) QueryRequest(input *QueryInput) QueryRequest
func (c *DynamoDB) ScanRequest(input *ScanInput) ScanRequest
func (c *DynamoDB) BatchGetItemRequest(input *BatchGetItemInput) BatchGetItemRequest
func (c *DynamoDB) BatchWriteItemRequest(input *BatchWriteItemInput) BatchWriteItemRequest

EC2 (Compute)

func (c *EC2) RunInstancesRequest(input *RunInstancesInput) RunInstancesRequest
func (c *EC2) TerminateInstancesRequest(input *TerminateInstancesInput) TerminateInstancesRequest
func (c *EC2) DescribeInstancesRequest(input *DescribeInstancesInput) DescribeInstancesRequest
func (c *EC2) StartInstancesRequest(input *StartInstancesInput) StartInstancesRequest
func (c *EC2) StopInstancesRequest(input *StopInstancesInput) StopInstancesRequest
func (c *EC2) RebootInstancesRequest(input *RebootInstancesInput) RebootInstancesRequest

Lambda (Serverless)

func (c *Lambda) InvokeRequest(input *InvokeInput) InvokeRequest
func (c *Lambda) InvokeAsyncRequest(input *InvokeAsyncInput) InvokeAsyncRequest
func (c *Lambda) CreateFunctionRequest(input *CreateFunctionInput) CreateFunctionRequest
func (c *Lambda) UpdateFunctionCodeRequest(input *UpdateFunctionCodeInput) UpdateFunctionCodeRequest
func (c *Lambda) UpdateFunctionConfigurationRequest(input *UpdateFunctionConfigurationInput) UpdateFunctionConfigurationRequest
func (c *Lambda) DeleteFunctionRequest(input *DeleteFunctionInput) DeleteFunctionRequest
func (c *Lambda) ListFunctionsRequest(input *ListFunctionsInput) ListFunctionsRequest

SQS (Message Queue)

func (c *SQS) SendMessageRequest(input *SendMessageInput) SendMessageRequest
func (c *SQS) SendMessageBatchRequest(input *SendMessageBatchInput) SendMessageBatchRequest
func (c *SQS) ReceiveMessageRequest(input *ReceiveMessageInput) ReceiveMessageRequest
func (c *SQS) DeleteMessageRequest(input *DeleteMessageInput) DeleteMessageRequest
func (c *SQS) DeleteMessageBatchRequest(input *DeleteMessageBatchInput) DeleteMessageBatchRequest
func (c *SQS) ChangeMessageVisibilityRequest(input *ChangeMessageVisibilityInput) ChangeMessageVisibilityRequest

SNS (Pub/Sub)

func (c *SNS) PublishRequest(input *PublishInput) PublishRequest
func (c *SNS) SubscribeRequest(input *SubscribeInput) SubscribeRequest
func (c *SNS) UnsubscribeRequest(input *UnsubscribeInput) UnsubscribeRequest
func (c *SNS) CreateTopicRequest(input *CreateTopicInput) CreateTopicRequest
func (c *SNS) DeleteTopicRequest(input *DeleteTopicInput) DeleteTopicRequest
func (c *SNS) ListSubscriptionsRequest(input *ListSubscriptionsInput) ListSubscriptionsRequest

Request Features

Context & Timeout

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

req := svc.GetObjectRequest(input)
req.SetContext(ctx)
resp, _ := req.Send() // Respects timeout/cancellation

Pagination

req := svc.ListObjectsV2Request(&s3.ListObjectsV2Input{
    Bucket: aws.String("my-bucket"),
})

p := req.Paginate()
for p.Next() {
    page := p.CurrentPage().(*s3.ListObjectsV2Output)
    for _, obj := range page.Contents {
        // Process object
    }
}
if err := p.Err(); err != nil {
    // Handle error
}

Presigned URLs

req := svc.GetObjectRequest(&s3.GetObjectInput{
    Bucket: aws.String("bucket"),
    Key:    aws.String("key"),
})
url, _ := req.Presign(15 * time.Minute) // Valid for 15 minutes

Error Handling

import "github.com/aws/aws-sdk-go-v2/aws/awserr"

resp, err := req.Send()
if err != nil {
    if aerr, ok := err.(awserr.Error); ok {
        fmt.Printf("Code: %s, Message: %s\n", aerr.Code(), aerr.Message())
        
        // Check for specific errors
        switch aerr.Code() {
        case s3.ErrCodeNoSuchBucket:
            // Handle missing bucket
        case s3.ErrCodeNoSuchKey:
            // Handle missing key
        }
        
        // Get HTTP status code
        if reqErr, ok := err.(awserr.RequestFailure); ok {
            fmt.Printf("Status: %d, RequestID: %s\n", 
                reqErr.StatusCode(), reqErr.RequestID())
        }
    }
}

High-Level Utilities

S3 Manager (Multipart Upload/Download)

// Package: service/s3/s3manager
func NewUploader(cfg aws.Config, options ...func(*Uploader)) *Uploader
func (u Uploader) Upload(input *UploadInput, options ...func(*Uploader)) (*UploadOutput, error)

func NewDownloader(cfg aws.Config, options ...func(*Downloader)) *Downloader
func (d Downloader) Download(w io.WriterAt, input *s3.GetObjectInput, options ...func(*Downloader)) (int64, error)

S3 Manager →

Configuration Patterns

Environment Variables

AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=AKID...
AWS_SECRET_ACCESS_KEY=SECRET...
AWS_SESSION_TOKEN=TOKEN...  # For temporary credentials

Shared Config Files

# ~/.aws/credentials
[default]
aws_access_key_id = AKID...
aws_secret_access_key = SECRET...

[production]
aws_access_key_id = AKID...
aws_secret_access_key = SECRET...

# ~/.aws/config
[default]
region = us-east-1

[profile production]
region = eu-west-1

Programmatic

cfg := aws.Config{
    Region:      "us-west-2",
    Credentials: aws.NewStaticCredentialsProvider("AKID", "SECRET", ""),
}

Important Notes for Agents

Pointer Usage

  • All optional fields use pointers: Use aws.String(), aws.Int64(), etc.
  • Check nil before dereferencing: Use aws.StringValue() for safety
  • Empty vs nil: nil omits field, empty pointer sends default value

Request Pattern

  • Requests are reusable: Can modify before sending
  • Requests are NOT thread-safe: Don't share across goroutines
  • Send() is blocking: Use goroutines for concurrent requests

Context Behavior

  • Context cancellation: Stops request mid-flight
  • Context timeout: Returns context.DeadlineExceeded
  • No context: Request has no timeout (uses HTTP client timeout)

Pagination

  • Always check p.Err(): Errors may occur mid-pagination
  • Current page type assertion: Cast to specific output type
  • Empty results: Next() returns false, check Err() to distinguish from error

Retry Behavior

  • Default: 3 attempts with exponential backoff
  • Retryable errors: 500s, throttling, network errors
  • Non-retryable: 400s (except throttling), authentication errors

Resources

Common Patterns

Service Client Creation

cfg, _ := external.LoadDefaultAWSConfig()
svc := s3.New(cfg)

Making Requests

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

With Context

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
req.SetContext(ctx)

With Pagination

p := req.Paginate()
for p.Next() {
    page := p.CurrentPage().(*<OutputType>)
}
err := p.Err()

Error Handling

if err != nil {
    if aerr, ok := err.(awserr.Error); ok {
        switch aerr.Code() {
        case <ServiceName>.ErrCode<ErrorName>:
            // Handle specific error
        }
    }
}

For comprehensive examples and edge cases, see examples.

Install with Tessl CLI

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

docs

index.md

tile.json