Page updated Jan 16, 2024

Use transfer acceleration

When you use Transfer Acceleration, additional data transfer charges might apply. For more information about pricing, see Amazon S3 pricing.

You can enable Transfer Acceleration for fast and secure transfer of files over long distances between your end user device and the S3 bucket. You can override the storage resource for this configuration and then leverage the useAccelerateEndpoint parameter to use the accelerated S3 endpoint.

Override storage resource

Start by overriding your storage resources to enable Transfer Acceleration on your S3 bucket.

1$ amplify override storage
2✅ Successfully generated "override.ts" folder at <project>/amplify/backend/storage/accelerated-bucket
3✔ Do you want to edit override.ts file now? (Y/n) · yes
4Edit the file in your editor: <project>/amplify/backend/storage/accelerated-bucket/override.ts

In the generated override.ts file use the following CDK snippet to enable transfer acceleration.

1// amplify/backend/storage/accelerated-bucket/override.ts
2import { AmplifyS3ResourceTemplate } from '@aws-amplify/cli-extensibility-helper';
4export function override(resources: AmplifyS3ResourceTemplate) {
5 resources.s3Bucket.accelerateConfiguration = {
6 accelerationStatus: 'Enabled'
7 }

Next, deploy this storage resource:

1amplify push

Use Transfer Acceleration on Storage Operations

You can use transfer acceleration when calling the following APIs:

  • getUrl
  • downloadData
  • downloadFile
  • uploadData
  • uploadFile

Set useAccelerateEndpoint to true in the corresponding Storage S3 plugin options to apply an accelerated S3 endpoint to the operation. For example, upload a file using transfer acceleration:

1import 'package:amplify_storage_s3/amplify_storage_s3.dart';
3Future<void> uploadFileUsingAcceleration(String filePath, String key) async {
4 final localFile = AWSFile.fromPath(filePath);
5 try {
6 final uploadFileOperation = Amplify.Storage.uploadFile(
7 localFile: localFile,
8 key: key,
9 options: const StorageUploadFileOptions(
10 pluginOptions: S3UploadFilePluginOptions(
11 useAccelerateEndpoint: true,
12 ),
13 ),
14 );
16 final result = await uploadFileOperation.result;
17 safePrint('Uploaded file: ${result.uploadedItem.key}');
18 } on StorageException catch (error) {
19 safePrint('Something went wrong uploading file: ${error.message}');
20 }