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

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

対応するpluginOptions"useAccelerateEndpoint"trueに設定することで、以下のいずれかのStorage APIでトランスファーアクセラレーションを使用できます:

  • getUrl(path:options:)
  • downloadData(path:options:)
  • downloadFile(path:local:options:)
  • uploadData(path:data:options:)
  • uploadFile(path:local:options:)
  • getUrl(key:options:) (非推奨)
  • downloadData(key:options:) (非推奨)
  • downloadFile(key:local:options:) (非推奨)
  • uploadData(key:data:options:) (非推奨)
  • uploadFile(key:local:options:) (非推奨)

たとえば、トランスファーアクセラレーションを使用してファイルをアップロードする場合:

let uploadTask = Amplify.Storage.uploadFile(
path: .fromString("public/example/key"),
local: aLocalFile,
options: .init(
pluginOptions: [
"useAccelerateEndpoint": true
]
)
)
let data = try await uploadTask.value
let uploadTask = Amplify.Storage.uploadFile(
key: aKey,
local: aLocalFile,
options: .init(
pluginOptions: [
"useAccelerateEndpoint": true
]
)
)
let data = try await uploadTask.value