Anda dapat mengonfigurasi bucket Amazon S3 agar berfungsi sebagai webhosting. Berikut adalah tutorial untuk mengaktifkan hosting web statis di Amazon S3
Buat bucket
1
aws s3 mb <S3Uri>
[cloudshell-user@ip-10-8-94-148 ~]$ aws s3 mb s3://mytopan
make_bucket: mytopanApabila dari AWS Management Console dapat mengikuti panduan Cara membuat Bucket di Amazon S3
Upload file HTML
1
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.htmlEdit Bucket policy
- Buat file policy.json dan edit seperti berikut
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
{ "Version": "2012-10-17", "Statement": [ { "Sid": "PublicReadGetObject", "Effect": "Allow", "Principal": "*", "Action": [ "s3:GetObject" ], "Resource": [ "arn:aws:s3:::Bucket-Name/*" ] } ] }
- Put Bucket Policy
1
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
}
}- Cek panduan Setting Bucket policy Amazon S3 jika melalui AWS Management Console
Setting Static website hosting
1
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
![webhost]()
- Pilih enable pada Static website hosting dan tentukan Index document
![webhost]()
- Terakhir klik Save changes


