前回見つけた Amazon Glacier from Python. を試しました。
ドキュメントはソース内部に書かれた数行のみ(とソース自体)とか、 boto の git 先端が必要だとか若干敷居が高いのですが、 eclipse 入れたり .Net SDK 入れるために Windows のインストールから始めることを考えればまだマシでしょう。
boto のインストールは net/py-boto があったので、それを丸パクリして local/py-boto2 を作成してインストールしました。 git 先端が必要な場合、どうやって入れるのが正義なんでしょうかね??
で glacier.py の先頭に
# Example: # # glacierconn = GlacierConnection(AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY) # writer = GlacierWriter(glacierconn, GLACIER_VAULT) # writer.write(somedata) # writer.write(someotherdata) # writer.close() # # Get the id of the newly created archive # archive_id = writer.get_archive_id()
と、具体例があるのでそれに準じて使えばいいのでしょう。
ということでこんな感じのコードを書いたのですが
#!/usr/pkg/bin/python2.7 AWSAccesskey="YOUR_AWS_ACCESS_KEY" AWSSecretAccesskey="YOUR_AWS_SECRET_ACCESS_KEY" AWSregion="AWS_REGION" VaultName="VAULT_NAME" from glacier import GlacierConnection from glacier import GlacierWriter f = open('./glacier.py','r') putsdata = f.read() f.close() glacierconn = GlacierConnection(AWSAccesskey, AWSSecretAccesskey, AWSregion) writer = GlacierWriter(glacierconn, VaultName) writer.write(putsdata) writer.close() print writer.get_archive_id()
実行すると、最後の get_archive_id() でちゃんと糞長いアーカイブ ID が拾えてるのにも関わらず、 AWS のコンソールにはなにも表示されないのです。 glacier.py はサイズに関わらず multipart upload を利用してアップするので試しに single upload を利用するのを作ったんだけど、結果は同じ…。
これは諦めてちゃんと SDK が用意されている eclipse でも入れなきゃなるまいか、と思いながら API を眺めていたら!!
Uploading an Archive in Amazon Glacier に
After you upload an archive, if you immediately download the vault inventory, it might not show the archive you uploaded in the list because Amazon Glacier prepares the vault inventory only about once a day.
…じゃーしょうがないですよネ! てなわけで待ってたらこんな感じに生えてきました。
しかし当然ながら保存したファイルの中身は確認できないようです(というか確認出来るのはトータルのサイズとアーカイブの個数だけ)
他にも Working with Archives in Amazon Glacier には
Updating an Archive in Amazon Glacier
After you upload an archive, you cannot update its content or its description. The only way you can update the archive content or its description is by deleting the archive and uploading another archive. Note that each time you upload an archive, Amazon Glacier returns to you a unique archive ID.
とか
Note
If you are an Amazon Simple Storage Service (Amazon S3) customer, you know that when you upload an object to a bucket, you can assign the object an object key such as MyDocument.txt or SomePhoto.jpg. In Amazon Glacier, you cannot assign a key name to the archives you upload.
とか楽しげなことが書いてあるので伊達に安いわけではないようで(笑)
ちなみに GlacierConnection の三番目の引数を指定しないとデフォルトの us-east-1(Virginia) になります。ここの指定は AWS コンソールの APN で確認出来るのでちゃんと指定してあげましょう。