S3

Bucket

S3 では Bucket と呼ばれる名前空間を作成する。Bucket 名はAWS 内ユニークである必要があり、作成後の変更もできない。

誰でも参照できるパーミッション設定となっていれば、サブディレクトリかサブドメインの URL でアクセスできる。

  1. (http|https)://s3-<region>.amazonaws.com/<bucket>/
  2. (http|https)://<bucket>.s3-<region>.amazonaws.com/

バケット名にはピリオドの使用を避けたほうが良い。S3 はワイルドカードの SSL 証明書を用いているので、HTTPS でサブドメインの URL を使うと、バケット名にピリオドが含まれているため、SSL 証明書エラーとなる。

REST API

S3 は REST API が提供されており、アクセスキーとシークレットキーを元に、リクエストヘッダ Authorization に所定の方法で暗号化したキーを含めれば、どこからでもアクセスできる。

コマンドラインからは s3cmd を使うとよい。

% yum --enablerepo=epel install s3cmd

% s3cmd --configure
....
Access key and Secret key are your identifiers for Amazon S3
Access Key: <Enter Your Access Key ....>
Secret Key: <Enter Your Secret Key ....>
....

# The command will create a file ~/.s3cfg as the user's setting
% cat  ~/.s3cfg
[default]
access_key = ...
bucket_location = US
...

% s3cmd ls
YYYY-mm-dd HH:MM  s3://example-bucket-foo
....

# The option -c allows to choose another configuration
% s3cmd -c /path/to/another/s3cfg ls
YYYY-mm-dd HH:MM  s3://example-bucket-bar
....

# The sub-command sync will synchronize a directory tree to S3
% s3cmd sync /path/to/dir/ s3://example-bucket-foo/path/to/dir/

# The option "--delete-removed" to delete files that are no longer present locally
% s3cmd sync --delete-removed /path/to/dir/ s3://example-bucket-foo/path/to/dir/