LoginSignup
1
0

More than 5 years have passed since last update.

aws-cli で S3ウェブサイトホスティングをする

Posted at

前提

  • S3 のwebサイトホスティングをcliでやってみようの巻。
  • 今回は bucket-acl のみで bucket-policy は使ってません。
  • cloudfrontは無しの構成です。

流れ

  1. バケット作成
  2. webサイトの設定をする
  3. コンテンツ置く
  4. 公開

手順

バケット作成

aws s3 mb s3://mybucket

webサイトホスティングの設定をする

以下のファイルを作成する(website.json)

website.json(例)
{
    "IndexDocument": {
        "Suffix": "index.html"
    },
    "ErrorDocument": {
        "Key": "error.html"
    }
}

上で作ったファイルをオプションで指定してwebサイト用の設定を投入

aws s3api put-bucket-website --bucket mybucket --website-configuration file://website.json

コンテンツ(html とか)置く

aws s3 cp index.html s3://mybucket/index.html --acl public-read
  • その他のファイルをアップロードする場合は、上のコマンドの index.html を置き換えてください。
  • 注意
    • aws s3api put-objectを使う場合はContent-type(text/html)やContent-Lengthオプションを設定して下さい。aws s3 cpであれば自動でいい感じに設定してくれますが、aws s3api put-objectだと設定してくれないです。

公開

aws s3api put-bucket-acl --bucket mybucket --acl public-read

アクセス

http://mybucket.s3-website-us-west-2.amazonaws.com/

  • バケットのURLと違うので気をつけて下さい。
  • リージョンはバケットを作ったリージョンに置き換えてください
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0