コンフィグ定義
$ sudo aws configure AWS Access Key ID [None]: xxxxxxxxxxxxxx AWS Secret Access Key [None]: xxxxxxxxxxxxxx Default region name [None]: ap-northeast-1 Default output format [None]: json
バケット作成
$ sudo aws s3 mb s3://example.net make_bucket: example.net
ファイルのアップロード
# aws s3 cp /var/www/vhosts/wpad.example.net/httpdocs/static/ s3://example.net --recursive
バケットへのWEB公開設定
# aws s3 website s3://example.net --index-document index.html
ポリシーの設定
# vi /root/public.json { "Version": "2012-10-17", "Id": "PublicRead", "Statement": [ { "Sid": "ReadAccess", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::example.net/*" } ] }
ポリシーの反映
# aws s3api put-bucket-policy --bucket example.net --policy file:///root/public.json
更新差分同期する場合
# aws s3 sync /var/www/vhosts/wpad.example.net/httpdocs/static/ s3://example.net --exact-timestamps
もくじ
cronとの連携
# vi /root/.aws/sync-s3.sh #/bin/bash export AWS_CONFIG_FILE="/root/.aws/config" export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxx export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxx /usr/bin/aws s3 sync /var/www/vhosts/wpad.example.net/httpdocs/static/ s3://example.net --exact-timestamps
# chmod 111 /root/.aws/sync-s3.sh
$ sudo vi /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO='' HOME=/ # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed # S3と同期 */1 * * * * root /root/.aws/sync-s3.sh
反映させます。
$ sudo service crond restart