1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Last updated at Posted at 2019-03-02

前提

  • 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

コンテンツ格納

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/

  • APIのエンドポイントと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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?