LoginSignup
5
0

More than 5 years have passed since last update.

AWS上に簡単なServerless環境を作ってみよう。②

Last updated at Posted at 2018-12-05

S3のバケット作成

1. サービス画面からS3をクリックする。

2. バケット作成をクリックし、以下のように情報を入れ、作成をクリックする。
※ほかの情報はディフォルトのまま
バケット名:自分の名前-serverlesswebsite
リージョン:アジアパシフィック(東京)

3. index.htmlの中身の"YOUR-API-GATEWAY-LINK-HERE"を先ほど作成したAPIGatewayのURLに変更する。

index.html
<html>
<script>

function myFunction() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
        document.getElementById("my-demo").innerHTML = this.responseText;
        }
    };
    xhttp.open("GET", "APIGateway URL ", true);
    xhttp.send();

}

</script>
<body><div align="center"><br><br><br><br>
<h1>Hello <span id="my-demo">Stylez AWS member!</span></h1>
<button onclick="myFunction()">Click me</button><br>
<img src="S3バケットURL"></div>
</body>
</html>

4. S3バケット画面から自分が作成したS3バケットにチェックを入れ、「パブリックアクセス設定を編集する」をクリックし、以下のように進める。
①「選択されたバケットのパブリックアクセス設定」は何も選択せずに保存をクリックする。
②「確認」と入力する。

5. 作成したバケットをクリックし、「アップロード」→「index.html、error.html」のファイルを追加する。

error.html
<html><body><h1>There has been an error!</h1></body></html>

S3ファイルアップロード②.PNG

6.「index.html、error.html」をそれぞれクリックし、「アクション」→「公開する」を選択する。
S3ファイルアップロード③.PNG

7.「プロパティ」→「Static website hosting」をクリックし、以下の情報を入力、保存する。
インデックスドキュメント :index.html
エラードキュメント:error.html

S3プロパティ変更.PNG

8.「Static website hosting」の保存できていることを確認した上で、S3エンドポイントをクリックする。
S3プロパティエンドポイントクリック.PNG

9.表示された画面からClick meを押してみる。
click me.PNG

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