Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated May 22, 2024

Maintenance ModeYou are viewing Amplify Gen 1 documentation. Amplify Gen 1 has entered maintenance mode and will reach end of life on May 1, 2027. New project should use Amplify Gen 2. For existing Gen 1 projects, a migration guide and tooling are available to help you upgrade. Switch to the latest Gen 2 docs →

トランスファーアクセラレーションを使用する

トランスファーアクセラレーションを使用する場合、追加のデータ転送料金が発生する可能性があります。料金の詳細については、Amazon S3の料金を参照してください。

トランスファーアクセラレーションを有効にして、エンドユーザーデバイスとS3バケット間で長距離にわたるファイルの高速かつ安全な転送を行うことができます。このこのこの構成のストレージリソースをオーバーライドしてから、useAccelerateEndpointパラメータを使用して、加速されたS3エンドポイントを活用できます。

ストレージリソースをオーバーライドする

S3バケットでトランスファーアクセラレーションを有効にするために、ストレージリソースをオーバーライドすることから始めます。

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

生成されたoverride.tsファイルで、次のCDKスニペットを使用してトランスファーアクセラレーションを有効にします。

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

次に、このストレージリソースをデプロイします。

amplify push

ストレージ操作でトランスファーアクセラレーションを使用する

次のAPIを呼び出す際にトランスファーアクセラレーションを使用できます:

  • getUrl
  • downloadData
  • downloadFile
  • uploadData
  • uploadFile

対応するStorage S3プラグインオプションでuseAccelerateEndpointtrueに設定して、加速されたS3エンドポイントを操作に適用します。たとえば、トランスファーアクセラレーションを使用してファイルをアップロードします:

import 'package:amplify_storage_s3/amplify_storage_s3.dart';
Future<void> uploadFileUsingAcceleration(String filePath, String path) async {
final localFile = AWSFile.fromPath(filePath);
try {
final uploadFileOperation = Amplify.Storage.uploadFile(
localFile: localFile,
path: const StoragePath.fromString(path),
options: const StorageUploadFileOptions(
pluginOptions: S3UploadFilePluginOptions(
useAccelerateEndpoint: true,
),
),
);
final result = await uploadFileOperation.result;
safePrint('Uploaded file: ${result.uploadedItem.path}');
} on StorageException catch (error) {
safePrint('Something went wrong uploading file: ${error.message}');
}
}