AWS SDK for Go v2 S3 package provides a comprehensive, type-safe API client for Amazon Simple Storage Service enabling all S3 operations including object management, bucket configuration, multipart uploads, presigned URLs, and advanced features like S3 Express One Zone and metadata tables
npx @tessl/cli install tessl/golang-github-com-aws-aws-sdk-go-v2--service-s3@1.92.0The AWS SDK for Go v2 S3 package provides a comprehensive, type-safe API client for Amazon Simple Storage Service (S3). This package enables Go applications to perform all S3 operations including object uploads/downloads, bucket management, multipart uploads, object tagging, versioning, lifecycle policies, encryption, access control, and advanced features like S3 Express One Zone and metadata tables.
go get github.com/aws/aws-sdk-go-v2/service/s3@v1.92.1github.com/aws/aws-sdk-go-v2/service/s3import (
"context"
"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"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
)package main
import (
"context"
"fmt"
"bytes"
"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 main() {
// Load AWS configuration
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
panic(err)
}
// Create S3 client
client := s3.NewFromConfig(cfg)
// Upload an object
_, err = client.PutObject(context.TODO(), &s3.PutObjectInput{
Bucket: aws.String("my-bucket"),
Key: aws.String("my-object.txt"),
Body: bytes.NewReader([]byte("Hello, S3!")),
})
if err != nil {
panic(err)
}
// Download an object
result, err := client.GetObject(context.TODO(), &s3.GetObjectInput{
Bucket: aws.String("my-bucket"),
Key: aws.String("my-object.txt"),
})
if err != nil {
panic(err)
}
defer result.Body.Close()
fmt.Println("Object downloaded successfully")
}The S3 SDK is organized into several key components:
s3.Client type that provides methods for all S3 operationsInitialize and configure the S3 client with various options including credentials, region, endpoint customization, retry behavior, and S3-specific features like transfer acceleration and path-style addressing.
Key APIs:
func New(options Options, optFns ...func(*Options)) *Client
func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *ClientSee Client Configuration for complete details.
Perform all object-level operations including uploading, downloading, copying, deleting objects, managing object metadata, tags, ACLs, retention, and legal holds.
Key APIs:
func (c *Client) PutObject(ctx context.Context, params *PutObjectInput, optFns ...func(*Options)) (*PutObjectOutput, error)
func (c *Client) GetObject(ctx context.Context, params *GetObjectInput, optFns ...func(*Options)) (*GetObjectOutput, error)
func (c *Client) DeleteObject(ctx context.Context, params *DeleteObjectInput, optFns ...func(*Options)) (*DeleteObjectOutput, error)
func (c *Client) CopyObject(ctx context.Context, params *CopyObjectInput, optFns ...func(*Options)) (*CopyObjectOutput, error)
func (c *Client) HeadObject(ctx context.Context, params *HeadObjectInput, optFns ...func(*Options)) (*HeadObjectOutput, error)Total Operations: 23 object operations
See Object Operations for complete details.
Manage multipart uploads for large objects, including initiating uploads, uploading parts, completing uploads, listing uploads and parts, and aborting incomplete uploads.
Key APIs:
func (c *Client) CreateMultipartUpload(ctx context.Context, params *CreateMultipartUploadInput, optFns ...func(*Options)) (*CreateMultipartUploadOutput, error)
func (c *Client) UploadPart(ctx context.Context, params *UploadPartInput, optFns ...func(*Options)) (*UploadPartOutput, error)
func (c *Client) CompleteMultipartUpload(ctx context.Context, params *CompleteMultipartUploadInput, optFns ...func(*Options)) (*CompleteMultipartUploadOutput, error)
func (c *Client) AbortMultipartUpload(ctx context.Context, params *AbortMultipartUploadInput, optFns ...func(*Options)) (*AbortMultipartUploadOutput, error)Total Operations: 7 multipart operations
See Multipart Upload Operations for complete details.
List objects, object versions, multipart uploads, and parts with support for pagination, filtering by prefix and delimiter, and continuation tokens.
Key APIs:
func (c *Client) ListObjectsV2(ctx context.Context, params *ListObjectsV2Input, optFns ...func(*Options)) (*ListObjectsV2Output, error)
func (c *Client) ListObjectVersions(ctx context.Context, params *ListObjectVersionsInput, optFns ...func(*Options)) (*ListObjectVersionsOutput, error)Total Operations: 4 list operations with paginator support
See List Operations for complete details.
Create, delete, and manage buckets including checking bucket existence, listing all buckets, and getting bucket location and metadata.
Key APIs:
func (c *Client) CreateBucket(ctx context.Context, params *CreateBucketInput, optFns ...func(*Options)) (*CreateBucketOutput, error)
func (c *Client) DeleteBucket(ctx context.Context, params *DeleteBucketInput, optFns ...func(*Options)) (*DeleteBucketOutput, error)
func (c *Client) HeadBucket(ctx context.Context, params *HeadBucketInput, optFns ...func(*Options)) (*HeadBucketOutput, error)
func (c *Client) ListBuckets(ctx context.Context, params *ListBucketsInput, optFns ...func(*Options)) (*ListBucketsOutput, error)Total Operations: 8 bucket operations
See Bucket Operations for complete details.
Manage bucket and object access control through ACLs, bucket policies, ABAC (attribute-based access control), public access block configuration, and ownership controls.
Key APIs:
func (c *Client) PutBucketPolicy(ctx context.Context, params *PutBucketPolicyInput, optFns ...func(*Options)) (*PutBucketPolicyOutput, error)
func (c *Client) GetBucketAcl(ctx context.Context, params *GetBucketAclInput, optFns ...func(*Options)) (*GetBucketAclOutput, error)
func (c *Client) PutPublicAccessBlock(ctx context.Context, params *PutPublicAccessBlockInput, optFns ...func(*Options)) (*PutPublicAccessBlockOutput, error)Total Operations: 15 access control operations
See Bucket Access Control for complete details.
Configure advanced bucket features including versioning, tagging, CORS, encryption, lifecycle rules, replication, notifications, website hosting, logging, request payment, transfer acceleration, analytics, metrics, inventory, and intelligent-tiering.
Key APIs:
func (c *Client) PutBucketVersioning(ctx context.Context, params *PutBucketVersioningInput, optFns ...func(*Options)) (*PutBucketVersioningOutput, error)
func (c *Client) PutBucketEncryption(ctx context.Context, params *PutBucketEncryptionInput, optFns ...func(*Options)) (*PutBucketEncryptionOutput, error)
func (c *Client) PutBucketLifecycleConfiguration(ctx context.Context, params *PutBucketLifecycleConfigurationInput, optFns ...func(*Options)) (*PutBucketLifecycleConfigurationOutput, error)
func (c *Client) PutBucketReplication(ctx context.Context, params *PutBucketReplicationInput, optFns ...func(*Options)) (*PutBucketReplicationOutput, error)Total Operations: 52 configuration operations
See Bucket Features and Configuration for complete details.
Generate presigned URLs for temporary, time-limited access to S3 operations without requiring AWS credentials, supporting both GET and POST methods.
Key APIs:
func NewPresignClient(c *Client, optFns ...func(*PresignOptions)) *PresignClient
func (c *PresignClient) PresignGetObject(ctx context.Context, params *GetObjectInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error)
func (c *PresignClient) PresignPutObject(ctx context.Context, params *PutObjectInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error)Total Methods: 5 presign methods + POST upload support
See Presigned URLs for complete details.
Use paginators for automatic pagination of list operations and waiters to poll operations until a desired state is reached.
Key APIs:
func NewListObjectsV2Paginator(client ListObjectsV2APIClient, params *ListObjectsV2Input, optFns ...func(*ListObjectsV2PaginatorOptions)) *ListObjectsV2Paginator
func NewBucketExistsWaiter(client HeadBucketAPIClient, optFns ...func(*BucketExistsWaiterOptions)) *BucketExistsWaiterTotal: 6 paginators, 2 waiters
See Paginators and Waiters for complete details.
The types package contains 257 exported types including enumerations, data structures for inputs/outputs, configuration objects, and error types.
Key Types:
type StorageClass string
type ServerSideEncryption string
type ObjectIdentifier struct
type Tag struct
type Grant struct
type LifecycleRule struct
type ReplicationRule structSee Types Reference for complete type definitions.
const ServiceID = "S3"
const ServiceAPIVersion = "2006-03-01"All operations return an error as the second return value. Common S3 errors from the types package include:
NoSuchBucket - Bucket does not existNoSuchKey - Object key does not existBucketAlreadyExists - Bucket name already takenNoSuchUpload - Multipart upload does not existInvalidObjectState - Object is in invalid state for operation