Note

s3のstatic website hostingをcliしてみる

まずコマンドをひとつひとつ確かめていこう。

バケットの作成

まずはバケットの作成

$ aws s3 mb s3://wnt.workapart.org/ make_bucket: s3://wnt.workapart.org/

うお、簡単すぎる。

static website hostingの値を変更する

# 設定する。json部分をシングルクォーテーションで囲むのがみそらしい $ aws s3api put-bucket-website --bucket "wnt.workapart.org" --website-configuration '{ "ErrorDocument": { "Key": "error.html" }, "IndexDocument": { "Suffix": "index.html" } }' # 一応設定出来ているか見てみる $ aws s3api get-bucket-website --bucket "wnt.workapart.org" { "RedirectAllRequestsTo": {}, "IndexDocument": { "Suffix": "index.html" }, "ErrorDocument": { "Key": "error.html" }, "RoutingRules": [] }

bucket policyの設定

$ aws s3api put-bucket-policy --bucket "wnt.workapart.org" --policy file://put-bucket-policy.json

jsonファイルはこんな感じ

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AddPerm", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::wnt.workapart.org/*" } ] }

ファイルの転送

aws s3 sync 元ファイル 転送先 ッて感じだろうか。

$ aws s3 sync /filepath/wnt/ s3://wnt.workapart.org/ upload: ./error.html to s3://wnt.workapart.org/error.html upload: ./index.html to s3://wnt.workapart.org/index.html

よしよしこれで、一発スクリプト化する素材が揃ったので、合体させてみようか。

これらのコマンドを重ねて.shにして(エラー処理なし)
今んとこうまく行ってるっぽいすね。

引っかかったところ

・put-bucket-policy
aws s3api put-bucket-policy — bucket “wnt.workapart.org” — policy put-bucket-policy.json
A client error (MalformedPolicy) occurred: Policies must be valid JSON and the first byte must be ‘{’
=> — policyのところのファイル名を put-bucket-policy.json -> file://put-bucket-policy.json
これ常識なのかしら、知らんかったってか超ハマった。