AWS SDK for Go v2 with 130+ service clients, Request/Send pattern, and context support.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
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.
dep ensure -add github.com/aws/aws-sdk-go-v2
# or: go get github.com/aws/aws-sdk-go-v2import (
"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)
}| Component | Purpose | Reference |
|---|---|---|
| aws | Config, helpers, request infrastructure | Core → |
| aws/external | Load config from env/files/IAM | Config → |
| aws/awserr | AWS error codes and handling | Errors → |
| aws/endpoints | Region/endpoint resolution | Endpoints → |
| aws/signer/v4 | SigV4 request signing | Signing → |
| service/* | 130+ AWS service clients | Services → |
// 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// 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// 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)// 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.Timefunc (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) ListObjectVersionsRequestfunc (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) BatchWriteItemRequestfunc (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) RebootInstancesRequestfunc (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) ListFunctionsRequestfunc (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) ChangeMessageVisibilityRequestfunc (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) ListSubscriptionsRequestctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
req := svc.GetObjectRequest(input)
req.SetContext(ctx)
resp, _ := req.Send() // Respects timeout/cancellationreq := 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
}req := svc.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String("bucket"),
Key: aws.String("key"),
})
url, _ := req.Presign(15 * time.Minute) // Valid for 15 minutesimport "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())
}
}
}// 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)AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=AKID...
AWS_SECRET_ACCESS_KEY=SECRET...
AWS_SESSION_TOKEN=TOKEN... # For temporary credentials# ~/.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-1cfg := aws.Config{
Region: "us-west-2",
Credentials: aws.NewStaticCredentialsProvider("AKID", "SECRET", ""),
}aws.String(), aws.Int64(), etc.aws.StringValue() for safetynil omits field, empty pointer sends default valuecontext.DeadlineExceededNext() returns false, check Err() to distinguish from errorcfg, _ := external.LoadDefaultAWSConfig()
svc := s3.New(cfg)req := svc.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String("my-bucket"),
Key: aws.String("my-key"),
})
resp, err := req.Send()ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
req.SetContext(ctx)p := req.Paginate()
for p.Next() {
page := p.CurrentPage().(*<OutputType>)
}
err := p.Err()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.