Amazon S3 から Cloud Storage への転送

このページでは、Amazon S3 から Cloud Storage への転送ジョブを作成して開始する方法について説明します。

権限を構成する

転送を作成する前に、Amazon S3 バケットに対する権限を構成する必要があります。詳細については、ソースへのアクセスを構成する: Amazon S3 をご覧ください。

また、次の Google Cloud エンティティの権限を構成する必要があります。

転送の作成に使用されるユーザー アカウント。これは、Google Cloud コンソールにログインするアカウント、または gcloud CLI の認証時に指定されたアカウントです。ユーザー アカウントは、通常のユーザー アカウントでも、ユーザーが管理するサービス アカウントでもかまいません。
Storage Transfer Service で使用される Google 管理のサービス アカウント(サービス エージェントとも呼ばれる)。通常、このアカウントは、project-PROJECT_NUMBER@storage-transfer-service.iam.gserviceaccount.com という形式を使用するメールアドレスで識別されます。

手順については、エージェントレス転送権限をご覧ください。

下り(外向き)オプション

Storage Transfer Service には、S3 データを Cloud Storage に転送する方法が複数用意されています。

下り(外向き)オプション 説明
デフォルトのエージェントレス このオプションでは、S3 からのマネージド エージェントレス転送を使用します。Amazon により下り(外向き)料金が課金されます。

このオプションを使用するには、このページの手順に従ってください。
CloudFront ディストリビューション Amazon CloudFront ディストリビューションを下り(外向き)パスとして使用します。CloudFront を介したデータ転送では、S3 から直接転送する場合と比較して、AWS の下り(外向き)コストが低くなる可能性があります。詳細については、CloudFront の料金S3 下り(外向き)料金をご覧ください。

CloudFront 経由で S3 から転送するの手順に沿って、ディストリビューションを設定し、転送を作成します。
マネージド プライベート ネットワーク Google 管理のネットワーク経由でデータを転送します。S3 の下り料金はかかりません。代わりに、GiB 単位のレートで Google Cloud に支払います。詳細については、料金のページをご覧ください。AWS からのオペレーション料金(例:LIST または GET 呼び出し)。詳細については料金をご覧ください。

マネージド プライベート ネットワークを介したすべてのプロジェクトの転送は同じ帯域幅を共有します。使用率が高い場合、転送が遅くなる可能性があります。大きなファイルの転送は、小さなファイルによる転送よりも影響を受けます。

このオプションを使用するには、このページの手順に従ってください。Google Cloud コンソールで [マネージド プライベート ネットワーク] オプションを指定するか、REST API で managedPrivateNetwork フィールドを指定します。gcloud CLI とクライアント ライブラリは、マネージド プライベート ネットワーク転送をサポートしていません。サポートされているリージョンをご覧ください。
エージェント主導 Amazon S3 を含むすべての S3 互換ストレージで有効です。S3 バケットにアクセスできるマシンにエージェント ソフトウェアをインストールすることで、ネットワーク パスと帯域幅を制御できます。このオプションには、エージェントとエージェント プールが必要です。

このオプションを使用するには、S3 互換ソースからの転送の手順に従ってください。

サポートされているリージョン

Storage Transfer Service では、次の Amazon S3 リージョンがサポートされます。

af-south-1
ap-east-1
ap-northeast-1
ap-northeast-2
ap-northeast-3
ap-south-1
ap-south-2
ap-southeast-1
ap-southeast-2
ap-southeast-3
ap-southeast-4
ca-central-1
ca-west-1
eu-central-1
eu-central-2
eu-north-1
eu-south-1
eu-south-2
eu-west-1
eu-west-2
eu-west-3
il-central-1
me-central-1
me-south-1
sa-east-1
us-east-1
us-east-2
us-west-1
us-west-2

マネージド プライベート ネットワークを使用した転送では、次の AWS リージョンがサポートされます。

us-east-1
us-east-2
us-west-1
us-west-2
ca-west-1
ca-central-1

転送オプション

S3 から Cloud Storage への転送では、次の Storage Transfer Service 機能を使用できます。

マニフェストを使用して特定のファイルを転送する
Storage Transfer Service に処理するファイルのリストを渡すことができます。詳細については、マニフェストを使用して特定のファイルまたはオブジェクトを転送するをご覧ください。
ストレージ クラスを指定する
転送先バケットのデータに使用する Cloud Storage ストレージ クラスを指定できます。REST の詳細については、 StorageClass オプションを参照するか、Google Cloud CLI で --custom-storage-class フラグを使用します。

転送先バケットで Autoclass が有効になっている場合、ストレージ クラスの設定は無視されます。Autoclass が有効になっている場合、バケットに転送されるオブジェクトは、最初は Standard Storage に設定されます。

メタデータの保持

S3 からファイルを転送する際に、Storage Transfer Service は特定の属性をカスタム メタデータとして保持できます。

保持できるメタデータと、転送の構成方法については、 メタデータの保持Amazon S3 から Cloud Storage のセクションをご覧ください。

イベント ドリブン転送
Storage Transfer Service は、Amazon SQS に送信された Amazon S3 Event Notifications をリッスンし、ソースのロケーションで追加または更新されたデータを自動的に転送できます。詳細については、イベント ドリブン転送をご覧ください。
ロギングとモニタリング
S3 からの転送は、Cloud Logging と Cloud Monitoring で確認できます。詳細については、Storage Transfer Service の Cloud Logging転送ジョブのモニタリングをご覧ください。Pub/Sub 通知を構成することもできます。

転送を作成する

Storage Transfer Service には、転送を作成するための複数のインターフェースが用意されています。

転送ジョブ名に、個人を特定できる情報(PII)やセキュリティ データなどの機密情報を含めないでください。リソース名は、他の Google Cloud リソースの名前に反映され、プロジェクト外部の Google 内部システムに公開される場合があります。

Google Cloud コンソール

  1. Google Cloud コンソールの [Storage Transfer Service] ページに移動します。

    Storage Transfer Service に移動

  2. [転送ジョブを作成] をクリックします。[転送ジョブの作成] ページが表示されます。

  3. [参照元の種類] で [Amazon S3] を選択します。

  4. [宛先の種類] として [Google Cloud Storage] を選択します。

  5. スケジュール モードを選択します。バッチ転送は、1 回限りまたはスケジュールに基づいて実行されます。イベント ドリブン転送は、ソースを継続的にモニタリングし、追加や変更が行われるとデータを転送します。

    イベント ドリブン転送を構成するには、イベント ドリブン転送の手順を実施します。

  6. [次のステップ] をクリックします。

  7. [バケットまたはフォルダの名前] フィールドに、転送元バケットの名前を入力します。

    このバケット名は、AWS Management Console に表示される名前です。

  8. CloudFront ディストリビューションを使用して S3 から転送する場合は、[CloudFront ドメイン] フィールドにディストリビューション ドメイン名を入力します。たとえば、https://dy1h2n3l4ob56.cloudfront.net のようにします。CloudFront ディストリビューションを構成するには、CloudFront 経由で S3 から転送するをご覧ください。

  9. この転送にマネージド プライベート ネットワークを使用するには、チェックボックスをオンにします。詳細については、下り(外向き)オプションをご覧ください。

  10. アマゾン ウェブ サービス(AWS)の認証方法を選択します。詳細については、ソースへのアクセスを構成する: Amazon S3 をご覧ください。

    • アクセスキー: [アクセスキー ID] フィールドにアクセスキーを入力し、[シークレット アクセスキー] フィールドにアクセス キーに関連付けられたシークレットを入力します。

    • ID 連携用の AWS IAM ロール: 次の構文で [AWS IAM ロールの ARN] フィールドに ARN を入力します。

      arn:aws:iam::ACCOUNT:role/ROLE-NAME-WITH-PATH
      

      ここで

      • ACCOUNT: ハイフンのない AWS アカウント ID。
      • ROLE-NAME-WITH-PATH: パスを含む AWS ロール名。

      ARN の詳細については、IAM ARN をご覧ください。

    • シークレット リソース: Secret Manager に保存されている Amazon 認証情報を使用するには、このオプションを選択します。リストからシークレットを選択するか、projects/PROJECT_NUMBER/secrets/SECRET_NAME の形式で手動で入力します。

  11. イベント ドリブン転送の場合は、Amazon SQS キューの ARN を入力します。これは、次の形式になります。

    arn:aws:sqs:us-east-1:1234567890:event-queue
    
  12. 必要に応じて、オブジェクトを前方一致でフィルタするか、最終更新日時でフィルタします。ソースの場所としてフォルダを指定した場合、接頭辞フィルタはそのフォルダを基準とします。たとえば、ソースが my-test-bucket/path/ の場合、file の一致フィルタには my-test-bucket/path/file で始まるすべてのファイルが含まれます。
  13. [次のステップ] をクリックします。

  14. [バケットまたはフォルダ] フィールドに、ソースバケットと(必要に応じて)フォルダ名を入力するか、[参照] をクリックして、現在のプロジェクトにある既存のバケットリストからバケットを選択します。新しいバケットを作成するには、[新しいバケットを作成] をクリックします。

  15. [次のステップ] をクリックします。

  16. 転送ジョブの設定を選択します。

    1. [説明] フィールドに、転送の説明を入力します。ジョブを区別できるように、意味のある一意の説明を入力することをおすすめします。

    2. [メタデータのオプション] で、デフォルトのオプションを使用するか、[オプションを表示して選択する] をクリックして、サポートされているすべてのメタデータの値を指定します。詳細については、メタデータの保持をご覧ください。

    3. [上書きの条件] で、次のいずれかを選択します。

      • 異なる場合: ソースファイルの名前が同じで ETag またはチェックサムの値が異なる場合、宛先ファイルを上書きします。

      • 常に: ソースファイルが同じ名前の場合、同一であっても常に宛先ファイルを上書きします。

    4. [削除のタイミング] で、次のいずれかを選択します。

      • なし: ソースと宛先のどちらからもファイルを削除しません。

      • 転送後にソースからファイルを削除する: 転送先に移行した後、ソースからファイルを削除します。

      • 転送元にもないファイルを転送先から削除する: 転送先の Cloud Storage バケット内のファイルが転送元にもない場合は、Cloud Storage バケットからファイルを削除します。

        このオプションにより、宛先の Cloud Storage バケットが移行元と完全に一致することが保証されます。

    5. [通知オプション] で、Pub/Sub トピックと通知するイベントを選択します。詳細については、Pub/Sub 通知をご覧ください。

  17. [次のステップ] をクリックします。

  18. スケジュール オプションを選択します。

    1. [1 回だけ実行] プルダウン リストから、次のいずれかを選択します。

      • 1 回だけ実行: 選択した時間に、1 回だけ転送を行います。

      • 毎日実行: 転送は毎日、選択した時刻に開始されます。

        オプションの [終了日] を入力することも、[終了日] を空白のままにして転送を継続的に実行することもできます。

      • 毎週実行: 選択した時間に毎週転送を実行します。

      • カスタム頻度で実行: 選択した頻度で転送を実行します。転送は、時間の間隔で定期的に繰り返すように設定できます。

        オプションの [終了日] を入力することも、[終了日] を空白のままにして転送を継続的に実行することもできます。

    2. [今すぐ開始] プルダウン リストから、次のいずれかを選択します。

      • 今すぐ開始: [作成] をクリックすると転送が開始されます。

      • 開始日: 選択した日時に転送を開始します。[カレンダー] をクリックして、カレンダーから開始日を選択します。

    3. 転送ジョブを作成するには、[作成] をクリックします。

gcloud CLI

新しい転送ジョブを作成するには、gcloud transfer jobs create コマンドを使用します。スケジュールまたは --do-not-run が指定されていない限り、新しいジョブを作成すると、指定された転送が開始します。

gcloud CLI では、CloudFront または Managed プライベート ネットワークを介した転送はサポートされていません。

gcloud transfer jobs create \
  s3://S3_BUCKET_NAME gs://STORAGE_BUCKET_NAME \
  --source-creds-file="relative_path/to/creds.json"

ここで

  • S3_BUCKET_NAME は、この転送のデータソースです。必要に応じて、パスを含めることができます: s3://S3_BUCKET_NAME/S3_FOLDER_PATH

  • STORAGE_BUCKET_NAME は、転送先の Cloud Storage バケットです。特定のディレクトリに転送するには、末尾のスラッシュを含めて gs://STORAGE_BUCKET_NAME/STORAGE_FOLDER_PATH/ を指定します。

  • --source-creds-file には、転送元の AWS または Azure 認証情報を含むマシン上のローカル ファイルへの相対パスを指定します。内容は次の JSON 形式にする必要があります。

    {
      "accessKeyId": string,
      "secretAccessKey": string
    }
    

上記以外に次のようなオプションがあります。

  • --do-not-run は、コマンドの送信時に Storage Transfer Service がジョブを実行しないようにします。ジョブを実行するには、更新してスケジュールを追加するか、jobs run を使用して手動で開始します。

  • --manifest-file には、ソースから転送するファイルのリストを含む Cloud Storage 内の CSV ファイルのパスを指定します。マニフェスト ファイルの形式については、マニフェストを使用して特定のファイルまたはオブジェクトを転送するをご覧ください。

  • ジョブ情報: --name--description を指定できます。

  • スケジュール: --schedule-starts--schedule-repeats-every--schedule-repeats-until、または --do-not-run を指定します。

  • オブジェクト条件: 条件を使用して、転送するオブジェクトを決定します。これには、--include-prefixes--exclude-prefixes--include-modified-[before | after]-[absolute | relative] の時間ベースの条件が含まれます。ソースでフォルダを指定した場合、接頭辞フィルタはそのフォルダを基準とします。詳細については、ソース オブジェクトを前方一致でフィルタするをご覧ください。

  • 転送オプション: 宛先ファイルを上書きするかどうか(--overwrite-when=different または always)、転送中または転送後に特定のファイルを削除するかどうか(--delete-from=destination-if-unique または source-after-transfer)を指定します。保持するメタデータ値--preserve-metadata)を指定することや、転送されたオブジェクトにストレージ クラスを設定することもできます(--custom-storage-class)。

  • 通知: --notification-pubsub-topic--notification-event-types--notification-payload-format を使用して、転送の Pub/Sub 通知を構成します。

  • Cloud Logging: --log-actions--log-action-states で Cloud Logging を有効にします。詳細については、Storage Transfer Service の Cloud Logging をご覧ください。

すべてのオプションを表示するには、gcloud transfer jobs create --help を実行するか、gcloud リファレンス ドキュメントをご覧ください。

REST

次のサンプルは、REST API を介して Storage Transfer Service を使用する方法を示しています。

Storage Transfer Service API を使用して転送ジョブを構成または編集する場合は、時刻を UTC で設定してください。転送ジョブのスケジュールの指定方法については、スケジュールをご覧ください。

転送ジョブを作成する場合は、Amazon S3 バケットソース名に bucketNames3:// 接頭辞を含めないでください。

エージェントレス転送

次の例では、標準のエージェントレス構成を使用して転送ジョブを作成します。詳細については、transferJobs.create のリファレンスをご覧ください。

POST https://storagetransfer.googleapis.com/v1/transferJobs
{
  "description": "DESCRIPTION",
  "status": "ENABLED",
  "projectId": "PROJECT_ID",
  "transferSpec": {
      "awsS3DataSource": {
          "bucketName": "AWS_SOURCE_NAME",
          "awsAccessKey": {
            "accessKeyId": "AWS_ACCESS_KEY_ID",
            "secretAccessKey": "AWS_SECRET_ACCESS_KEY"
          }
      },
      "gcsDataSink": {
          "bucketName": "GCS_SINK_NAME"
      }
  }
}

その他の認証オプションについては、送信元へのアクセスを構成する: Amazon S3 をご覧ください。

CloudFront ディストリビューション

CloudFront ディストリビューションを介して S3 から転送する場合は、ディストリビューション ドメイン名を transferSpec.awsS3DataSource.cloudfrontDomain フィールドの値として指定します。

POST https://storagetransfer.googleapis.com/v1/transferJobs
{
  "description": "DESCRIPTION",
  "status": "ENABLED",
  "projectId": "PROJECT_ID",
  "transferSpec": {
      "awsS3DataSource": {
          "bucketName": "AWS_SOURCE_NAME",
          "cloudfrontDomain": "https://dy1h2n3l4ob56.cloudfront.net",
          "awsAccessKey": {
            "accessKeyId": "AWS_ACCESS_KEY_ID",
            "secretAccessKey": "AWS_SECRET_ACCESS_KEY"
          }
      },
      "gcsDataSink": {
          "bucketName": "GCS_SINK_NAME"
      }
  }
}

マネージド プライベート ネットワーク

Google が管理するプライベート ネットワークを使用して S3 から転送するには、transferSpec.awsS3DataSource.managedPrivateNetwork フィールドを指定します。

POST https://storagetransfer.googleapis.com/v1/transferJobs
{
  "description": "DESCRIPTION",
  "status": "ENABLED",
  "projectId": "PROJECT_ID",
  "transferSpec": {
      "awsS3DataSource": {
          "bucketName": "AWS_SOURCE_NAME",
          "managedPrivateNetwork": TRUE,
          "awsAccessKey": {
            "accessKeyId": "AWS_ACCESS_KEY_ID",
            "secretAccessKey": "AWS_SECRET_ACCESS_KEY"
          }
      },
      "gcsDataSink": {
          "bucketName": "GCS_SINK_NAME"
      }
  }
}

クライアント ライブラリ

次のサンプルは、Go、Java、Node.js、Python のプログラムで Storage Transfer Service を使用する方法を示しています。

転送ジョブをプログラムで構成または編集する場合は、時刻を UTC で設定してください。転送ジョブのスケジュールの指定方法について詳しくは、スケジュールをご覧ください。

Storage Transfer Service クライアント ライブラリの詳細については、Storage Transfer Service クライアント ライブラリ スタートガイドをご覧ください。

Amazon S3 から Cloud Storage への転送

この例では、Amazon S3 から Cloud Storage バケットにファイルを移動します。

転送ジョブを作成する場合は、Amazon S3 バケットソース名に bucketNames3:// 接頭辞を含めないでください。

Storage Transfer Service クライアント ライブラリは、CloudFront またはマネージド プライベート ネットワークを介した転送をサポートしていません。

Go

import (
	"context"
	"fmt"
	"io"
	"os"
	"time"

	storagetransfer "cloud.google.com/go/storagetransfer/apiv1"
	"cloud.google.com/go/storagetransfer/apiv1/storagetransferpb"
	"google.golang.org/genproto/googleapis/type/date"
	"google.golang.org/genproto/googleapis/type/timeofday"
)

func transferFromAws(w io.Writer, projectID string, awsSourceBucket string, gcsSinkBucket string) (*storagetransferpb.TransferJob, error) {
	// Your Google Cloud Project ID
	// projectID := "my-project-id"

	// The name of the Aws bucket to transfer objects from
	// awsSourceBucket := "my-source-bucket"

	// The name of the GCS bucket to transfer objects to
	// gcsSinkBucket := "my-sink-bucket"

	ctx := context.Background()
	client, err := storagetransfer.NewClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("storagetransfer.NewClient: %w", err)
	}
	defer client.Close()

	// A description of this job
	jobDescription := "Transfers objects from an AWS bucket to a GCS bucket"

	// The time to start the transfer
	startTime := time.Now().UTC()

	// The AWS access key credential, should be accessed via environment variable for security
	awsAccessKeyID := os.Getenv("AWS_ACCESS_KEY_ID")

	// The AWS secret key credential, should be accessed via environment variable for security
	awsSecretKey := os.Getenv("AWS_SECRET_ACCESS_KEY")

	req := &storagetransferpb.CreateTransferJobRequest{
		TransferJob: &storagetransferpb.TransferJob{
			ProjectId:   projectID,
			Description: jobDescription,
			TransferSpec: &storagetransferpb.TransferSpec{
				DataSource: &storagetransferpb.TransferSpec_AwsS3DataSource{
					AwsS3DataSource: &storagetransferpb.AwsS3Data{
						BucketName: awsSourceBucket,
						AwsAccessKey: &storagetransferpb.AwsAccessKey{
							AccessKeyId:     awsAccessKeyID,
							SecretAccessKey: awsSecretKey,
						}},
				},
				DataSink: &storagetransferpb.TransferSpec_GcsDataSink{
					GcsDataSink: &storagetransferpb.GcsData{BucketName: gcsSinkBucket}},
			},
			Schedule: &storagetransferpb.Schedule{
				ScheduleStartDate: &date.Date{
					Year:  int32(startTime.Year()),
					Month: int32(startTime.Month()),
					Day:   int32(startTime.Day()),
				},
				ScheduleEndDate: &date.Date{
					Year:  int32(startTime.Year()),
					Month: int32(startTime.Month()),
					Day:   int32(startTime.Day()),
				},
				StartTimeOfDay: &timeofday.TimeOfDay{
					Hours:   int32(startTime.Hour()),
					Minutes: int32(startTime.Minute()),
					Seconds: int32(startTime.Second()),
				},
			},
			Status: storagetransferpb.TransferJob_ENABLED,
		},
	}
	resp, err := client.CreateTransferJob(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("failed to create transfer job: %w", err)
	}
	if _, err = client.RunTransferJob(ctx, &storagetransferpb.RunTransferJobRequest{
		ProjectId: projectID,
		JobName:   resp.Name,
	}); err != nil {
		return nil, fmt.Errorf("failed to run transfer job: %w", err)
	}
	fmt.Fprintf(w, "Created and ran transfer job from %v to %v with name %v", awsSourceBucket, gcsSinkBucket, resp.Name)
	return resp, nil
}

Java

古いサンプルをお探しの場合Storage Transfer Service 移行ガイドをご覧ください。


import com.google.storagetransfer.v1.proto.StorageTransferServiceClient;
import com.google.storagetransfer.v1.proto.TransferProto.CreateTransferJobRequest;
import com.google.storagetransfer.v1.proto.TransferTypes.AwsAccessKey;
import com.google.storagetransfer.v1.proto.TransferTypes.AwsS3Data;
import com.google.storagetransfer.v1.proto.TransferTypes.GcsData;
import com.google.storagetransfer.v1.proto.TransferTypes.Schedule;
import com.google.storagetransfer.v1.proto.TransferTypes.TransferJob;
import com.google.storagetransfer.v1.proto.TransferTypes.TransferJob.Status;
import com.google.storagetransfer.v1.proto.TransferTypes.TransferSpec;
import com.google.type.Date;
import com.google.type.TimeOfDay;
import java.io.IOException;
import java.util.Calendar;

public class TransferFromAws {

  // Creates a one-off transfer job from Amazon S3 to Google Cloud Storage.
  public static void transferFromAws(
      String projectId,
      String jobDescription,
      String awsSourceBucket,
      String gcsSinkBucket,
      long startDateTime)
      throws IOException {

    // Your Google Cloud Project ID
    // String projectId = "your-project-id";

    // A short description of this job
    // String jobDescription = "Sample transfer job from S3 to GCS.";

    // The name of the source AWS bucket to transfer data from
    // String awsSourceBucket = "yourAwsSourceBucket";

    // The name of the GCS bucket to transfer data to
    // String gcsSinkBucket = "your-gcs-bucket";

    // What day and time in UTC to start the transfer, expressed as an epoch date timestamp.
    // If this is in the past relative to when the job is created, it will run the next day.
    // long startDateTime =
    //     new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2000-01-01 00:00:00").getTime();

    // The ID used to access your AWS account. Should be accessed via environment variable.
    String awsAccessKeyId = System.getenv("AWS_ACCESS_KEY_ID");

    // The Secret Key used to access your AWS account. Should be accessed via environment variable.
    String awsSecretAccessKey = System.getenv("AWS_SECRET_ACCESS_KEY");

    // Set up source and sink
    TransferSpec transferSpec =
        TransferSpec.newBuilder()
            .setAwsS3DataSource(
                AwsS3Data.newBuilder()
                    .setBucketName(awsSourceBucket)
                    .setAwsAccessKey(
                        AwsAccessKey.newBuilder()
                            .setAccessKeyId(awsAccessKeyId)
                            .setSecretAccessKey(awsSecretAccessKey)))
            .setGcsDataSink(GcsData.newBuilder().setBucketName(gcsSinkBucket))
            .build();

    // Parse epoch timestamp into the model classes
    Calendar startCalendar = Calendar.getInstance();
    startCalendar.setTimeInMillis(startDateTime);
    // Note that this is a Date from the model class package, not a java.util.Date
    Date startDate =
        Date.newBuilder()
            .setYear(startCalendar.get(Calendar.YEAR))
            .setMonth(startCalendar.get(Calendar.MONTH) + 1)
            .setDay(startCalendar.get(Calendar.DAY_OF_MONTH))
            .build();
    TimeOfDay startTime =
        TimeOfDay.newBuilder()
            .setHours(startCalendar.get(Calendar.HOUR_OF_DAY))
            .setMinutes(startCalendar.get(Calendar.MINUTE))
            .setSeconds(startCalendar.get(Calendar.SECOND))
            .build();
    Schedule schedule =
        Schedule.newBuilder()
            .setScheduleStartDate(startDate)
            .setScheduleEndDate(startDate)
            .setStartTimeOfDay(startTime)
            .build();

    // Set up the transfer job
    TransferJob transferJob =
        TransferJob.newBuilder()
            .setDescription(jobDescription)
            .setProjectId(projectId)
            .setTransferSpec(transferSpec)
            .setSchedule(schedule)
            .setStatus(Status.ENABLED)
            .build();

    // Create a Transfer Service client
    StorageTransferServiceClient storageTransfer = StorageTransferServiceClient.create();

    // Create the transfer job
    TransferJob response =
        storageTransfer.createTransferJob(
            CreateTransferJobRequest.newBuilder().setTransferJob(transferJob).build());

    System.out.println("Created transfer job from AWS to GCS:");
    System.out.println(response.toString());
  }
}

Node.js


// Imports the Google Cloud client library
const {
  StorageTransferServiceClient,
} = require('@google-cloud/storage-transfer');

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of the Google Cloud Platform Project that owns the job
// projectId = 'my-project-id'

// A useful description for your transfer job
// description = 'My transfer job'

// AWS S3 source bucket name
// awsSourceBucket = 'my-s3-source-bucket'

// AWS Access Key ID
// awsAccessKeyId = 'AKIA...'

// AWS Secret Access Key
// awsSecretAccessKey = 'HEAoMK2.../...ku8'

// Google Cloud Storage destination bucket name
// gcsSinkBucket = 'my-gcs-destination-bucket'

// Creates a client
const client = new StorageTransferServiceClient();

/**
 * Creates a one-time transfer job from Amazon S3 to Google Cloud Storage.
 */
async function transferFromS3() {
  // Setting the start date and the end date as the same time creates a
  // one-time transfer
  const now = new Date();
  const oneTimeSchedule = {
    day: now.getDate(),
    month: now.getMonth() + 1,
    year: now.getFullYear(),
  };

  // Runs the request and creates the job
  const [transferJob] = await client.createTransferJob({
    transferJob: {
      projectId,
      description,
      status: 'ENABLED',
      schedule: {
        scheduleStartDate: oneTimeSchedule,
        scheduleEndDate: oneTimeSchedule,
      },
      transferSpec: {
        awsS3DataSource: {
          bucketName: awsSourceBucket,
          awsAccessKey: {
            accessKeyId: awsAccessKeyId,
            secretAccessKey: awsSecretAccessKey,
          },
        },
        gcsDataSink: {
          bucketName: gcsSinkBucket,
        },
      },
    },
  });

  console.log(
    `Created and ran a transfer job from '${awsSourceBucket}' to '${gcsSinkBucket}' with name ${transferJob.name}`
  );
}

transferFromS3();

Python

古いサンプルをお探しの場合Storage Transfer Service 移行ガイドをご覧ください。

from datetime import datetime

from google.cloud import storage_transfer


def create_one_time_aws_transfer(
    project_id: str,
    description: str,
    source_bucket: str,
    aws_access_key_id: str,
    aws_secret_access_key: str,
    sink_bucket: str,
):
    """Creates a one-time transfer job from Amazon S3 to Google Cloud
    Storage."""

    client = storage_transfer.StorageTransferServiceClient()

    # The ID of the Google Cloud Platform Project that owns the job
    # project_id = 'my-project-id'

    # A useful description for your transfer job
    # description = 'My transfer job'

    # AWS S3 source bucket name
    # source_bucket = 'my-s3-source-bucket'

    # AWS Access Key ID
    # aws_access_key_id = 'AKIA...'

    # AWS Secret Access Key
    # aws_secret_access_key = 'HEAoMK2.../...ku8'

    # Google Cloud Storage destination bucket name
    # sink_bucket = 'my-gcs-destination-bucket'

    now = datetime.utcnow()
    # Setting the start date and the end date as
    # the same time creates a one-time transfer
    one_time_schedule = {"day": now.day, "month": now.month, "year": now.year}

    transfer_job_request = storage_transfer.CreateTransferJobRequest(
        {
            "transfer_job": {
                "project_id": project_id,
                "description": description,
                "status": storage_transfer.TransferJob.Status.ENABLED,
                "schedule": {
                    "schedule_start_date": one_time_schedule,
                    "schedule_end_date": one_time_schedule,
                },
                "transfer_spec": {
                    "aws_s3_data_source": {
                        "bucket_name": source_bucket,
                        "aws_access_key": {
                            "access_key_id": aws_access_key_id,
                            "secret_access_key": aws_secret_access_key,
                        },
                    },
                    "gcs_data_sink": {
                        "bucket_name": sink_bucket,
                    },
                },
            }
        }
    )

    result = client.create_transfer_job(transfer_job_request)
    print(f"Created transferJob: {result.name}")