Hosting a Static Website

Hosting a Static Website

HOSTING A STATIC WEBSITE

In this lab, I created an S3 bucket and configured it for static website hosting. Static websites have fixed content with no backend processing. They can contain HTML pages, images, style sheets, and all files needed to render a website. However, static websites do not use server-side scripting or a database. If you want your static webpages to provide interactivity and run programming logic, you can use JavaScript that runs in the user's web browser.

You can easily host a static website on Amazon S3 by uploading the content and making it publicly accessible. No servers are needed, and you can use Amazon S3 to store and retrieve any amount of data at any time, from anywhere on the web.

To complete this task, simply start by;

  1. Navigate to the AWS Management Console and select S3.?
  2. Choose Create Bucket (Note: S3 bucket name is globally unique, and all AWS accounts share the namespace. After you create a bucket, the name of that bucket cannot be used by another AWS account in any AWS Region unless you delete the bucket).
  3. For Bucket Name (Webiste<123>). Replace <123> with random numbers. (Public access to S3 buckets is blocked by default. Because the files in this static website need to be accessible to the internet and permit public access).
  4. Select the Region of your choice.
  5. In the Object Ownership section, select ACLs enabled then verify Bucket Owner preferred is selected.
  6. Clear Block all Public access, then select the box that states I acknowledge that the current setting may result in this bucket and the objects within become public.
  7. Choose Create Bucket.
  8. Optional: ?You can use tags to add additional information to the bucket such as a project code, cost center or owner.
  9. Choose the name of your new bucket.
  10. Choose the Properties tab
  11. Scroll to the Tags panel
  12. Choose Edit, then choose Add Tag and enter
  13. Name the Key- Value with names of your choice. e.g. Key- Department, Value -Finance.?
  14. Choose Save Changes, to save the tag.

Now configure the bucket for static website hosting. Stay in the Properties Console.

  1. Scroll to the Static Website Hosting panel.
  2. Choose Edit
  3. Configure the following settings Static web hosting: Enable Hosting type: Host a static website Index document: index.html, Error document: error.html
  4. Choose Save Changes
  5. In the Static Website hosting panel, choose the link under the Bucket website endpoint. (Note: You will receive a 403 forbidden message because the bucket permissions have not been configured yet. Keep this tab open in your web browser so you can return to it later). The Bucket has now been configured to host a static website.

UPLOADING CONTENT TO YOUR BUCKET

To complete this task, you will upload the file that will serve as your static website to the bucket. You probably should have the files for your static websites which include the html, css and javascript files. Ensure that each file keeps the same file name including the extension (.html, .css, .js).

  1. Return to the Amazon S3 console and in the website<123> bucket you created earlier, choose the Objects tab.
  2. Choose Upload
  3. Choose Add files
  4. Locate and select the files (.html, .css, .js)
  5. If prompted, choose I acknowledge that existing object with the same file will be overwritten.?
  6. Choose Upload. (Your files are uploaded to the bucket)
  7. Choose Close.

ENABLING ACCESS TO THE OBJECTS

Objects that are stored in S3 are private by default, this ensures that your organization’s data remains secure.?

In this task, you will make the uploaded objects publicly accessible. First, confirm that the objects are currently private.

  1. Refresh the webpage with the 403 forbidden message. You should still see the forbidden message. This response is expected. The response indicates that the static content is still hosted by S3 but the content is private.

You can make Objects in Amazon S3 public in two different ways:

  • To make either a bucket public or a specific directory in a bucket public, use a bucket policy.
  • To make individual Objects in a bucket public, use an access control list (ACL).

It is normally safer to make individual Objects public because this avoids accidentally making other Objects public. However, if you know that the entire bucket contains no sensitive information, you can use a bucket policy.?

Now, Configure the individual Objects to be publicly accessible.

  1. In the web browser tab with the Amazon S3 Console, select all three Objects.
  2. In the Actions menu, choose Make Public via ACL. (A list of three Objects is displayed)
  3. Choose Make Public.

Your Static website is now publicly accessible. Refresh the website page that has the 403 forbidden message. You should now see the static website hosted by Amazon S3.

UPDATING THE WEBSITE

You can update the website by editing the file and uploading it again to the S3 bucket.?

Amazon S3 is an Object storage, so you must upload the whole file. This action replaces the existing object in your bucket. You cannot edit the content of an object, instead, the whole object must be replaced. Use the Action Menu to choose the Make Public via ACL option again.

?

Dare Omotosho AWS CCP SAA

Experienced Solutions Architect | Tech Mentor

1 年

Awesome

要查看或添加评论,请登录

Obasaju Winner的更多文章

社区洞察

其他会员也浏览了