Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat s3 transfer manager v2 PutObject #2733

Open
wants to merge 2 commits into
base: feat-transfer-manager-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions feature/s3/transfermanager/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package transfermanager

import (
"context"

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

// S3APIClient defines an interface doing S3 client side operations for transfer manager
type S3APIClient interface {
PutObject(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error)
UploadPart(context.Context, *s3.UploadPartInput, ...func(*s3.Options)) (*s3.UploadPartOutput, error)
CreateMultipartUpload(context.Context, *s3.CreateMultipartUploadInput, ...func(*s3.Options)) (*s3.CreateMultipartUploadOutput, error)
CompleteMultipartUpload(context.Context, *s3.CompleteMultipartUploadInput, ...func(*s3.Options)) (*s3.CompleteMultipartUploadOutput, error)
AbortMultipartUpload(context.Context, *s3.AbortMultipartUploadInput, ...func(*s3.Options)) (*s3.AbortMultipartUploadOutput, error)
}
51 changes: 51 additions & 0 deletions feature/s3/transfermanager/api_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package transfermanager

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

const userAgentKey = "s3-transfer"

// defaultMaxUploadParts is the maximum allowed number of parts in a multi-part upload
// on Amazon S3.
const defaultMaxUploadParts = 10000

// defaultPartSizeBytes is the default part size when transferring objects to/from S3
const minPartSizeBytes = 1024 * 1024 * 8

// defaultMultipartUploadThreshold is the default size threshold in bytes indicating when to use multipart upload.
const defaultMultipartUploadThreshold = 1024 * 1024 * 16

// defaultTransferConcurrency is the default number of goroutines to spin up when
// using PutObject().
const defaultTransferConcurrency = 5

// Client provides the API client to make operations call for Amazon Simple
// Storage Service's Transfer Manager
// It is safe to call Client methods concurrently across goroutines.
type Client struct {
options Options
}

// New returns an initialized Client from the client Options. Provide
// more functional options to further configure the Client
func New(s3Client S3APIClient, opts Options, optFns ...func(*Options)) *Client {
opts.S3 = s3Client
for _, fn := range optFns {
fn(&opts)
}

resolveConcurrency(&opts)
resolvePartSizeBytes(&opts)
resolveChecksumAlgorithm(&opts)
resolveMultipartUploadThreshold(&opts)

return &Client{
options: opts,
}
}

// NewFromConfig returns a new Client from the provided s3 config
func NewFromConfig(s3Client S3APIClient, cfg aws.Config, optFns ...func(*Options)) *Client {
return New(s3Client, Options{}, optFns...)
}
Loading
Loading