AWS Security ChangesHomeSearch

AWS AmazonS3 documentation change

Service: AmazonS3 · 2025-08-22 · Documentation low

File: AmazonS3/latest/userguide/track-mpu.md

Summary

Updated Java code example to use AWS SDK for Java 2.x with S3AsyncClient and ExecutionInterceptor instead of deprecated TransferManager/ProgressListener from SDK 1.x

Security assessment

The changes modernize the code example to use current SDK practices but do not address any specific security vulnerabilities or introduce security features. The migration from TransferManager to S3AsyncClient is a routine SDK version update.

Diff

diff --git a/AmazonS3/latest/userguide/track-mpu.md b/AmazonS3/latest/userguide/track-mpu.md
index 31b794012..357228ed7 100644
--- a//AmazonS3/latest/userguide/track-mpu.md
+++ b//AmazonS3/latest/userguide/track-mpu.md
@@ -16,14 +15,0 @@ Java
-    
-    TransferManager tm = new TransferManager(new ProfileCredentialsProvider());        
-    
-    PutObjectRequest request = new PutObjectRequest(
-      		existingBucketName, keyName, new File(filePath));
-    
-    // Subscribe to the event and provide event handler.        
-    request.setProgressListener(new ProgressListener() {
-    			public void progressChanged(ProgressEvent event) {
-    				System.out.println("Transferred bytes: " + 
-    						event.getBytesTransfered());
-                 }
-    });
-
@@ -32 +18 @@ Java
-The following Java code uploads a file and uses the `ProgressListener` to track the upload progress. For instructions on how to create and test a working sample, see [Getting Started](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/getting-started.html) in the AWS SDK for Java Developer Guide. 
+The following Java code uploads a file and uses the `ExecutionInterceptor` to track the upload progress. For instructions on how to create and test a working sample, see [Getting Started](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html) in the AWS SDK for Java 2.x Developer Guide. 
@@ -35 +21 @@ The following Java code uploads a file and uses the `ProgressListener` to track
-    import java.io.File;
+    import java.nio.file.Paths;
@@ -37,7 +23,7 @@ The following Java code uploads a file and uses the `ProgressListener` to track
-    import com.amazonaws.AmazonClientException;
-    import com.amazonaws.auth.profile.ProfileCredentialsProvider;
-    import com.amazonaws.event.ProgressEvent;
-    import com.amazonaws.event.ProgressListener;
-    import com.amazonaws.services.s3.model.PutObjectRequest;
-    import com.amazonaws.services.s3.transfer.TransferManager;
-    import com.amazonaws.services.s3.transfer.Upload;
+    import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
+    import software.amazon.awssdk.core.async.AsyncRequestBody;
+    import software.amazon.awssdk.core.interceptor.Context;
+    import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
+    import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
+    import software.amazon.awssdk.services.s3.S3AsyncClient;
+    import software.amazon.awssdk.services.s3.model.PutObjectRequest;
@@ -46,0 +33,14 @@ The following Java code uploads a file and uses the `ProgressListener` to track
+        static class ProgressListener implements ExecutionInterceptor {
+            private long transferredBytes = 0;
+    
+            @Override
+            public void beforeTransmission(Context.BeforeTransmission context, ExecutionAttributes executionAttributes) {
+                if (context.httpRequest().firstMatchingHeader("Content-Length").isPresent()) {
+                    String contentLength = context.httpRequest().firstMatchingHeader("Content-Length").get();
+                    long partSize = Long.parseLong(contentLength);
+                    transferredBytes += partSize;
+                    System.out.println("Transferred bytes: " + transferredBytes);
+                }
+            }
+        }
+    
@@ -52 +52,4 @@ The following Java code uploads a file and uses the `ProgressListener` to track
-            TransferManager tm = new TransferManager(new ProfileCredentialsProvider());        
+            S3AsyncClient s3Client = S3AsyncClient.builder()
+                    .credentialsProvider(ProfileCredentialsProvider.create())
+                    .overrideConfiguration(c -> c.addExecutionInterceptor(new ProgressListener()))
+                    .build();
@@ -57,2 +60,6 @@ The following Java code uploads a file and uses the `ProgressListener` to track
-            PutObjectRequest request = new PutObjectRequest(
-            		existingBucketName, keyName, new File(filePath));
+            PutObjectRequest request = PutObjectRequest.builder()
+                    .bucket(existingBucketName)
+                    .key(keyName)
+                    .build();
+    
+            AsyncRequestBody requestBody = AsyncRequestBody.fromFile(Paths.get(filePath));
@@ -63,9 +70 @@ The following Java code uploads a file and uses the `ProgressListener` to track
-            request.setGeneralProgressListener(new ProgressListener() {
-    			@Override
-    			public void progressChanged(ProgressEvent progressEvent) {
-    				System.out.println("Transferred bytes: " + 
-    						progressEvent.getBytesTransferred());
-    			}
-    		});
-    
-            // TransferManager processes all transfers asynchronously, 
+            // S3AsyncClient processes all transfers asynchronously,
@@ -73 +72 @@ The following Java code uploads a file and uses the `ProgressListener` to track
-            Upload upload = tm.upload(request);
+            var upload = s3Client.putObject(request, requestBody);
@@ -77,2 +76,2 @@ The following Java code uploads a file and uses the `ProgressListener` to track
-            	upload.waitForCompletion();
-            } catch (AmazonClientException amazonClientException) {
+                upload.join();
+            } catch (Exception exception) {
@@ -80 +79,3 @@ The following Java code uploads a file and uses the `ProgressListener` to track
-            	amazonClientException.printStackTrace();
+                exception.printStackTrace();
+            } finally {
+                s3Client.close();