- AWS Code Sample demonstrates how to enable and use transfer acceleration with Amazon S3.

/** * Copyright 2018-2019, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.regions.Regions; import; import; import; import; import; import; public class TransferAcceleration { public static void main(String[] args) { Regions clientRegion = Regions.DEFAULT_REGION; String bucketName = "*** Bucket name ***"; String keyName = "*** Key name ***"; try { // Create an Amazon S3 client that is configured to use the accelerate endpoint. AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withRegion(clientRegion) .withCredentials(new ProfileCredentialsProvider()) .enableAccelerateMode() .build(); // Enable Transfer Acceleration for the specified bucket. s3Client.setBucketAccelerateConfiguration( new SetBucketAccelerateConfigurationRequest(bucketName, new BucketAccelerateConfiguration( BucketAccelerateStatus.Enabled))); // Verify that transfer acceleration is enabled for the bucket. String accelerateStatus = s3Client.getBucketAccelerateConfiguration( new GetBucketAccelerateConfigurationRequest(bucketName)) .getStatus(); System.out.println("Bucket accelerate status: " + accelerateStatus); // Upload a new object using the accelerate endpoint. s3Client.putObject(bucketName, keyName, "Test object for transfer acceleration"); System.out.println("Object \"" + keyName + "\" uploaded with transfer acceleration."); } catch (AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 couldn't process // it, so it returned an error response. e.printStackTrace(); } catch (SdkClientException e) { // Amazon S3 couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3. e.printStackTrace(); } } }

Sample Details

Service: s3

Last tested: 2019-01-28

Author: AWS

Type: full-example