Skip to main content
  1. Posts/

Setting static website Amazon S3

·2 mins·
aws aws
Table of Contents

Anda dapat mengonfigurasi bucket Amazon S3 agar berfungsi sebagai webhosting. Berikut adalah tutorial untuk mengaktifkan hosting web statis di Amazon S3

Buat bucket
#

aws s3 mb <S3Uri>
[cloudshell-user@ip-10-8-94-148 ~]$ aws s3 mb s3://mytopan
make_bucket: mytopan

Apabila dari AWS Management Console dapat mengikuti panduan Cara membuat Bucket di Amazon S3

Upload file HTML
#

aws s3 sync localpath <S3Uri>
[cloudshell-user@ip-10-8-94-148 ~]$ aws s3 sync public_html/ s3://mytopan/
upload: public_html/404.html to s3://mytopan/index.html

Edit Bucket policy
#

  • Buat file policy.json dan edit seperti berikut
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::Bucket-Name/*"
            ]
        }
    ]
}
  • Put Bucket Policy
aws s3api put-bucket-policy --bucket bucketname --policy file://policy.json
[cloudshell-user@ip-10-8-86-217 ~]$ aws s3api put-bucket-policy --bucket mytopan --policy file://policy.json
[cloudshell-user@ip-10-8-86-217 ~]$ aws s3api get-bucket-policy --bucket mytopan
{
    "Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"PublicReadGetObject\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::mytopan/*\"}]}"
}
[cloudshell-user@ip-10-8-86-217 ~]$ aws s3api get-bucket-policy-status --bucket mytopan
{
    "PolicyStatus": {
        "IsPublic": true
    }
}

Setting Static website hosting
#

aws s3 website <S3Uri> --index-document index.html --error-document error.html
[cloudshell-user@ip-10-8-86-217 ~]$ aws s3 website s3://mytopan --index-document index.html 

[cloudshell-user@ip-10-8-86-217 ~]$ aws s3api get-bucket-website --bucket mytopan
{
    "IndexDocument": {
        "Suffix": "index.html"
    }
}

Jika melalui AWS Management Console

  • Pilih bucket
  • Klik Properties Tab
  • Pada Static website hosting klik Edit
    edit static webhosting
  • Pilih enable pada Static website hosting dan tentukan Index document
    tentukan index document
  • Terakhir klik Save changes

Test Akses
#

test akses

Related

Cara membuat Bucket di Amazon S3
·1 min
aws aws
Manage Amazon S3 dengan AWS CLI
·2 mins
aws aws
Setup AWS CloudFront distribution dengan S3 Origin
·2 mins
aws aws
Setting Bucket policy Amazon S3
·2 mins
aws aws
Cara membuat Users dan Groups AWS
·1 min
aws aws
Install AWS CLI di Linux
·1 min
aws aws