@Konboi memo

主に技術に関してつらつらと。

s3cmd で ec2からs3へファイルをアップロードしようとしたらハマった

s3cmdのインストール

sudo yum -y --enablerepo epel install s3cmd

s3cmd の設定

下記コマンドで初期設定を行います。

s3cmd --configure

アクセスキーやシークレットキーなどを設定します。

Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.

Access key and Secret key are your identifiers for Amazon S3
Access Key: 
Secret Key: 

Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password:
Path to GPG program [/usr/bin/gpg]:

When using secure HTTPS protocol all communication with Amazon S3
servers is protected from 3rd party eavesdropping. This method is
slower than plain HTTP and can't be used if you're behind a proxy
Use HTTPS protocol [No]:

On some networks all internet access must go through a HTTP proxy.
Try setting it here if you can't conect to S3 directly
HTTP Proxy server name:

New settings:
  Access Key: 
  Secret Key:
  Encryption password:
  Path to GPG program: 
  Use HTTPS protocol: 
  HTTP Proxy server name:
  HTTP Proxy server port: 

Test access with supplied credentials? [Y/n] 
Please wait...
Success. Your access key and secret key worked fine :-)

Now verifying that encryption works...
Not configured. Never mind.

Save settings? [y/N] :

設定完了

設定が無事終われば s3cmd ls で作ったs3のbucketの一覧が参照できます。

s3cmd ls
2013-06-04 06:17  s3://sample-bucket

ハマったこと

ここまでは順調にいったのですが、s3 へファイルをアップロードするときにハマりました。

このようにputで対象のbucketへファイルを置こうとすると

s3cmd put sample.txt s3://sample-bucket/
./sample.txt -> s3://sample-bucket  [1 of 1]
   57344 of 5100090     1% in    2s    24.61 kB/s  failed
WARNING: Upload failed: /sample.txt ([Errno 32] Broken pipe)
WARNING: Retrying on lower speed (throttle=0.00)
WARNING: Waiting 3 sec...
./sample.txt -> s3://sample-bucket  [1 of 1]
   57344 of 5100090     1% in    2s    21.64 kB/s  failed
WARNING: Upload failed: /sample.txt ([Errno 32] Broken pipe)
WARNING: Retrying on lower speed (throttle=0.01)
WARNING: Waiting 6 sec...
./sample.txt -> s3://sample-bucket  [1 of 1]
   53248 of 5100090     1% in    1s    41.09 kB/s  failed
WARNING: Upload failed: /sample.txt ([Errno 32] Broken pipe)
WARNING: Retrying on lower speed (throttle=0.05)
WARNING: Waiting 9 sec...
./sample.txt -> s3://sample-bucket  [1 of 1]
   45056 of 5100090     0% in    1s    30.43 kB/s  failed
WARNING: Upload failed: /sample.txt ([Errno 32] Broken pipe)
WARNING: Retrying on lower speed (throttle=0.25)
WARNING: Waiting 12 sec...
./sample.txt -> s3://sample-bucket  [1 of 1]
   20480 of 5100090     0% in    1s    16.51 kB/s  failed
WARNING: Upload failed: /sample.txt ([Errno 32] Broken pipe)
WARNING: Retrying on lower speed (throttle=1.25)
WARNING: Waiting 15 sec...
./sample.txt -> s3://sample-bucket  [1 of 1]
    8192 of 5100090     0% in    1s     5.41 kB/s  failed
ERROR: Upload of './sample.txt' failed too many times. Skipping that file.

この様なエラーがでてアップロードできません。 調べてみると

雑多なインフラエンジニア日記

こちらのブログと同様の現象っぽかったたので、調べてみました。

s3cmd la 

実行してみると

3cmd la
WARNING: Redirected to: sample-bucket.s3-ap-northeast-1.amazonaws.com
                       DIR   s3://sample-bucket/sample/
.s3cfg

をみてみると、ブログの通りリージョンがUSの設定になっていました。

こちらのとおりUS設定のところを東京リージョンに変更すると問題なくアップロードできました。

めでたしめでたし。

まとめ

  • ブログなかったら大分はまってたかも。

  • c3cmdからじゃなくてコード経由でアップロードする方法を調べる。

  • gemとかでもこのへん気をつけた方がいいかも。

Amazon Web Services クラウドデザインパターン 設計ガイド
玉川 憲 片山 暁雄 鈴木 宏康
日経BP
売り上げランキング: 17,101