Upload to S3 using transfer acceleration enabled

127 views Asked by At

I am trying to upload file from my app to S3. App specs: Grails 3.3.15, Java 8, AWS SDK v1 Current upload API: TransferManager with PutObject

Following is the controller code that is called from gsp (view) via AJAX request to upload the file from input type of file:

def s3AccessKey = 'XXXXXXXXXX'
def s3SecretKey = 'XXXXXXXXX '
def s3BucketName = 'dummyBucketName'
MultipartFile uploadedFile = request.getFile({file name})
// Create an Amazon S3 client that is configured to use the accelerate endpoint.
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                        .withRegion(clientRegion)
                        .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
                        .enableAccelerateMode()
                        .build()

// Enable Transfer Acceleration for the specified bucket.
s3Client.setBucketAccelerateConfiguration(new SetBucketAccelerateConfigurationRequest(s3BucketName, new BucketAccelerateConfiguration(BucketAccelerateStatus.Enabled)))

// Verify that transfer acceleration is enabled for the bucket.
String accelerateStatus = s3Client.getBucketAccelerateConfiguration(new GetBucketAccelerateConfigurationRequest(s3BucketName))
                            .getStatus()
log.info("Bucket accelerate status: " + accelerateStatus)

// Upload the file data with content length.
ObjectMetadata metadata = new ObjectMetadata()
metadata.setContentLength(contentLength)
s3Client.putObject(s3BucketName, s3ObjectKey, uploadedFile.getInputStream(), metadata)

TransferManager tm = TransferManagerBuilder.standard()
                        .withS3Client(s3Client)
                        .build();

log.info("Object upload started");
Upload upload = tm.upload(s3BucketName, s3ObjectKey, uploadedFile.getInputStream(), metadata);
upload.waitForCompletion();
log.info("File uploaded with transfer acceleration.")

I have attempted to enable transfer acceleration to upload the file, but I observe no difference in the upload time. I believe there should be a way to achieve this.

I am considering that transfer acceleration might still not be enabled for some reason.

Does the use of ARN: def s3AcceleratedBucketName = 'dummyBucketName.s3-accelerate.amazonaws.com'

I am unsure how to use that, and I'm not certain if it makes any difference.

The following are the questions that I am seeking clarification on:

  • Is using an ARN mandatory for enabling transfer acceleration?

  • Is using a multipart file better, or is a direct file path faster for large files (5+ GB)?

Appreciate any code pointers if something is wrong or incomplete.

Thank you!

0

There are 0 answers