Skip to content

Commit 80b6ae5

Browse files
committed
Migrate Go v2 S3 examples from deprecated feature/s3/manager to feature/s3/transfermanager
The feature/s3/manager package was deprecated in February 2026 and replaced by feature/s3/transfermanager. This commit migrates all Go SDK v2 examples to use the new package. Key changes: - Replace manager.NewUploader/NewDownloader with transfermanager.New (unified client) - Replace uploader.Upload with tmClient.UploadObject (new UploadObjectInput type) - Replace downloader.Download with tmClient.DownloadObject (new DownloadObjectInput type) - Replace manager.NewWriteAtBuffer with tmtypes.NewWriteAtBuffer - Configure PartSize via Options.PartSizeBytes on the client - Use transfermanager/types.ChecksumAlgorithmSha256 for checksum config - Update go.mod dependencies from feature/s3/manager to feature/s3/transfermanager Files modified: - gov2/s3/actions/bucket_basics.go (UploadLargeObject, DownloadLargeObject) - gov2/s3/go.mod - gov2/workflows/s3_object_lock/actions/s3_actions.go (S3Actions struct, UploadObject) - gov2/workflows/s3_object_lock/actions/s3_actions_test.go - gov2/workflows/s3_object_lock/workflows/s3_object_lock.go - gov2/workflows/s3_object_lock/go.mod
1 parent ac9d32f commit 80b6ae5

6 files changed

Lines changed: 29 additions & 26 deletions

File tree

gov2/s3/actions/bucket_basics.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717
"time"
1818

1919
"github.com/aws/aws-sdk-go-v2/aws"
20-
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
20+
"github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager"
21+
tmtypes "github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager/types"
2122
"github.com/aws/aws-sdk-go-v2/service/s3"
2223
"github.com/aws/aws-sdk-go-v2/service/s3/types"
2324
"github.com/aws/smithy-go"
@@ -162,15 +163,15 @@ func (basics BucketBasics) UploadFile(ctx context.Context, bucketName string, ob
162163

163164
// snippet-start:[gov2.s3.Upload]
164165

165-
// UploadLargeObject uses an upload manager to upload data to an object in a bucket.
166-
// The upload manager breaks large data into parts and uploads the parts concurrently.
166+
// UploadLargeObject uses the S3 transfer manager to upload data to an object in a bucket.
167+
// The transfer manager breaks large data into parts and uploads the parts concurrently.
167168
func (basics BucketBasics) UploadLargeObject(ctx context.Context, bucketName string, objectKey string, largeObject []byte) error {
168169
largeBuffer := bytes.NewReader(largeObject)
169170
var partMiBs int64 = 10
170-
uploader := manager.NewUploader(basics.S3Client, func(u *manager.Uploader) {
171-
u.PartSize = partMiBs * 1024 * 1024
171+
tmClient := transfermanager.New(basics.S3Client, func(o *transfermanager.Options) {
172+
o.PartSizeBytes = partMiBs * 1024 * 1024
172173
})
173-
_, err := uploader.Upload(ctx, &s3.PutObjectInput{
174+
_, err := tmClient.UploadObject(ctx, &transfermanager.UploadObjectInput{
174175
Bucket: aws.String(bucketName),
175176
Key: aws.String(objectKey),
176177
Body: largeBuffer,
@@ -234,18 +235,19 @@ func (basics BucketBasics) DownloadFile(ctx context.Context, bucketName string,
234235

235236
// snippet-start:[gov2.s3.Download]
236237

237-
// DownloadLargeObject uses a download manager to download an object from a bucket.
238-
// The download manager gets the data in parts and writes them to a buffer until all of
238+
// DownloadLargeObject uses the S3 transfer manager to download an object from a bucket.
239+
// The transfer manager gets the data in parts and writes them to a buffer until all of
239240
// the data has been downloaded.
240241
func (basics BucketBasics) DownloadLargeObject(ctx context.Context, bucketName string, objectKey string) ([]byte, error) {
241242
var partMiBs int64 = 10
242-
downloader := manager.NewDownloader(basics.S3Client, func(d *manager.Downloader) {
243-
d.PartSize = partMiBs * 1024 * 1024
243+
tmClient := transfermanager.New(basics.S3Client, func(o *transfermanager.Options) {
244+
o.PartSizeBytes = partMiBs * 1024 * 1024
244245
})
245-
buffer := manager.NewWriteAtBuffer([]byte{})
246-
_, err := downloader.Download(ctx, buffer, &s3.GetObjectInput{
247-
Bucket: aws.String(bucketName),
248-
Key: aws.String(objectKey),
246+
buffer := tmtypes.NewWriteAtBuffer([]byte{})
247+
_, err := tmClient.DownloadObject(ctx, &transfermanager.DownloadObjectInput{
248+
Bucket: aws.String(bucketName),
249+
Key: aws.String(objectKey),
250+
WriterAt: buffer,
249251
})
250252
if err != nil {
251253
log.Printf("Couldn't download large object from %v:%v. Here's why: %v\n",

gov2/s3/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24
55
require (
66
github.com/aws/aws-sdk-go-v2 v1.41.5
77
github.com/aws/aws-sdk-go-v2/config v1.27.33
8-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.18
8+
github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.1.0
99
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.3
1010
github.com/aws/smithy-go v1.24.2
1111
github.com/awsdocs/aws-doc-sdk-examples/gov2/demotools v0.0.0-20240907001412-a9375541143b

gov2/workflows/s3_object_lock/actions/s3_actions.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import (
1515
"time"
1616

1717
"github.com/aws/aws-sdk-go-v2/aws"
18-
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
18+
"github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager"
19+
tmtypes "github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager/types"
1920
"github.com/aws/aws-sdk-go-v2/service/s3"
2021
"github.com/aws/aws-sdk-go-v2/service/s3/types"
2122
"github.com/aws/smithy-go"
@@ -24,7 +25,7 @@ import (
2425
// S3Actions wraps S3 service actions.
2526
type S3Actions struct {
2627
S3Client *s3.Client
27-
S3Manager *manager.Uploader
28+
S3Manager *transfermanager.Client
2829
}
2930

3031
// snippet-end:[gov2.workflows.s3.ObjectLock.S3Actions.struct]
@@ -303,16 +304,16 @@ func (actor S3Actions) PutObjectRetention(ctx context.Context, bucket string, ke
303304

304305
// snippet-start:[gov2.workflows.s3.ObjectLock.UploadObject]
305306

306-
// UploadObject uses the S3 upload manager to upload an object to a bucket.
307+
// UploadObject uses the S3 transfer manager to upload an object to a bucket.
307308
func (actor S3Actions) UploadObject(ctx context.Context, bucket string, key string, contents string) (string, error) {
308309
var outKey string
309-
input := &s3.PutObjectInput{
310+
input := &transfermanager.UploadObjectInput{
310311
Bucket: aws.String(bucket),
311312
Key: aws.String(key),
312313
Body: bytes.NewReader([]byte(contents)),
313-
ChecksumAlgorithm: types.ChecksumAlgorithmSha256,
314+
ChecksumAlgorithm: tmtypes.ChecksumAlgorithmSha256,
314315
}
315-
output, err := actor.S3Manager.Upload(ctx, input)
316+
output, err := actor.S3Manager.UploadObject(ctx, input)
316317
if err != nil {
317318
var noBucket *types.NoSuchBucket
318319
if errors.As(err, &noBucket) {

gov2/workflows/s3_object_lock/actions/s3_actions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/aws/aws-sdk-go-v2/aws"
16-
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
16+
"github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager"
1717
"github.com/aws/aws-sdk-go-v2/service/s3"
1818
"github.com/aws/aws-sdk-go-v2/service/s3/types"
1919
"github.com/aws/smithy-go"
@@ -142,7 +142,7 @@ func TestUploadObject(t *testing.T) {
142142
ctx, stubber, actor := enterTest()
143143
defer testtools.ExitTest(stubber, t)
144144

145-
actor.S3Manager = manager.NewUploader(actor.S3Client)
145+
actor.S3Manager = transfermanager.New(actor.S3Client)
146146
expectedErr, stubErr := wrapErr(&types.NoSuchBucket{})
147147
checksum := types.ChecksumAlgorithmSha256
148148
stubber.Add(stubs.StubPutObject("amzn-s3-demo-bucket", "test-key", &checksum, stubErr))

gov2/workflows/s3_object_lock/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24
55
require (
66
github.com/aws/aws-sdk-go-v2 v1.41.5
77
github.com/aws/aws-sdk-go-v2/config v1.27.33
8-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.18
8+
github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.1.0
99
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.3
1010
github.com/aws/smithy-go v1.24.2
1111
github.com/awsdocs/aws-doc-sdk-examples/gov2/demotools v0.0.0-20240907001412-a9375541143b

gov2/workflows/s3_object_lock/workflows/s3_object_lock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"s3_object_lock/actions"
1515

1616
"github.com/aws/aws-sdk-go-v2/aws"
17-
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
17+
"github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager"
1818
"github.com/aws/aws-sdk-go-v2/service/s3"
1919
"github.com/aws/aws-sdk-go-v2/service/s3/types"
2020
"github.com/awsdocs/aws-doc-sdk-examples/gov2/demotools"
@@ -36,7 +36,7 @@ func NewObjectLockScenario(sdkConfig aws.Config, questioner demotools.IQuestione
3636
s3Actions: &actions.S3Actions{S3Client: s3.NewFromConfig(sdkConfig)},
3737
sdkConfig: sdkConfig,
3838
}
39-
scenario.s3Actions.S3Manager = manager.NewUploader(scenario.s3Actions.S3Client)
39+
scenario.s3Actions.S3Manager = transfermanager.New(scenario.s3Actions.S3Client)
4040
scenario.resources.init(scenario.s3Actions, questioner)
4141
return scenario
4242
}

0 commit comments

Comments
 (0)