Host a Website on AWS S3

Some websites are becoming static websites which means they run without server-side code and consist of only HTML, CSS and JavaScript. Since there's no server-side code, there is no reason to host them on a traditional server.

"If the things are open and you have an intense" you can learn things! with my intense to learn, I tried and deployed my static website on the s3 bucket. Here's the way I did,

Note: when you create an S3 bucket Name is global. So, have to consider creating a unique name.
if your Domain name is www.fayasak.com. you must create the bucket exactly like your domain name
I am going to use AWS CLI for deployment.

if you did not install AWS CLI click the URL 

1. Create the bucket
[fayasak@controller]$ aws s3api create-bucket --bucket fayasak.com --acl public-read
2. Amazon needs to know what is our index document and error document. Though, type AWS S3 API CLI command to enable the "Static website hosting" property of our bucket along with our index and error document
[fayasak@controller]$ aws s3 website s3://www.fayasak.com/ --index-document index.html --error-document 404.html
3. Now you can access the website via http://www.f.com.s3-webyasak.com.s3-wasite-us-east-1.amazonaws.com/.
since I did not upload my files and policy my website show error.

let's upload my website and apply a publically accessible bucket policy to my website.

1. create and apply policy the bucket
[fayasak@controller]$ cat policy.jason{ "Version": "2008-10-17", "Id": "PolicyForPublicWebsiteContent", "Statement": [ { "Sid": "PublicReadGetObject", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::www.fayasak.com/*" } ] }# Apply policy to the bucket[fayasak@controller]$ s3api put-bucket-policy --bucket www.fayasak.com --policy file://policy.json
Note: "Principal": { "AWS": "*" } lines opens up our bucket to the world
2. Uploading Our Static Website
[fayasak@controller]$ aws s3 cp ./website/ s3://www.fayasak.com
3. Test the website
[fayasak@controller]$ curl www.fayasak.com.s3-website-us-east-1.amazonaws.com


, , ,

No comments:

Post a Comment