LoginSignup
6
4

More than 5 years have passed since last update.

s3からgcsへのファイル同期について

Posted at

概要

日時でs3からgcsへファイルをコピーする業務要件のため急遽作りました。

本来はGCPのStorage Transfer Serviceを使用していたのですが、今月頭あたりから酷く遅延を起こすようになったので実装することにしました。

使い方

  • awsはアクセスキーで、gcpはサービスアカウントのキーファイルで認証を行いgsutil rsyncでバケット間を同期します。
  • コンテナ内に認証情報を持たせたくないので、全ての情報は環境変数で指定するような作りになってます。
    • そのためサービスアカウントのキーファイルはbase64でエンコードしてください。
  • ローカル実行だと処理が遅いので、基本クラウド上で動作させてください。FargateなりGCEなり。
  • https://cloud.google.com/storage/docs/gsutil/commands/rsync

Note 2: If you are synchronizing a large amount of data between clouds you might consider setting up a Google Compute Engine account and running gsutil there. Since cross-provider gsutil data transfers flow through the machine where gsutil is running, doing this can make your transfer run significantly faster than running gsutil on your local workstation.

ENV Description
CLOUDSDK_CORE_PROJECT GCPのプロジェクトID
GCLOUD_SERVICE_KEY サービスアカウントのキーファイルを、Base64でエンコードした文字列
AWS_ACCESS_KEY_ID awsのアクセスキー
AWS_SECRET_ACCESS_KEY awsのシークレットアクセスキー
S3_BUCKET s3のバケット名
GCS_BUCKET gcsのバケット名
// build image
$ docker build -t sync_gcs_from_s3 .

// run container 
$ docker run \
    -e CLOUDSDK_CORE_PROJECT=${gcp_project_id} \
    -e GCLOUD_SERVICE_KEY=ABCDEFGHIJKLMN...... \
    -e AWS_ACCESS_KEY_ID=XXXXXXXX \
    -e AWS_SECRET_ACCESS_KEY=XXXXXXXX \
    -e S3_BUCKET=${s3_bucket_name} \
    -e GCS_BUCKET=${gcs_bucket_name} \
    sync_gcs_from_s3
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4