0
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?

S3 の Static Website Hosting を使ってサイトを公開してみた話

Posted at

AWS で「とりあえず簡単に Web サイトを公開したい!」という時に便利なのが S3 の Static Website Hostingです。
S3 バケットに HTML を置くだけで、そのまま Web サイトとして公開できます。

今回は、index.html / error.html を配置して、S3 バケットを Web サイトとして公開するまでをまとめました。

1. バケットを作成する

まずは S3 のバケットを作成します。

Block Public Access を OFF にする

image.png

※Static Website Hosting で公開する場合は、パブリックアクセスを許可する必要があります

2. Static Website Hosting を ON にする

バケットのプロパティから Static website hosting を有効化します。

  • Hosting type: Enable
  • Index document: index.html
  • Error document: error.html

image.png

有効化すると、公開用の エンドポイント URL が発行されます。

3. バケットポリシーを設定して公開を許可する

S3 バケットはデフォルトで非公開なので、Web サイトとして機能させるには
GetObject をすべてのユーザーに公開する必要があります。

以下のようなバケットポリシーを設定します。

image.png

これにより、誰でもバケット内のファイルへアクセス可能になります。

4. index.html / error.html をアップロード

最後に、公開用の HTML ファイルを S3 バケットにアップロードします。

image.png

内容は下記です

index.html

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>My S3 Static Site</title>
</head>
<body>
    <h1>ようこそ!</h1>
    <p>S3 Static Website Hosting のデモサイトです。</p>
</body>
</html>

error.html

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>Error - Page Not Found</title>
</head>
<body>
    <h1>ページが見つかりません</h1>
    <p>指定されたページは存在しない可能性があります。</p>
</body>
</html>

5. エンドポイント URL にアクセスする

アップロード後、Static Website Hosting のエンドポイント URL を開くと…

image.png

無事、Web サイトとしてアクセスできました!

0
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
0
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?