AWS: How to use S3

AWS: How to use S3

Overview

This article will explain how to make and use S3 buckets on AWS. S3 stands for Simple Storage Service. It is a storage service that is simple to configure to hold many files.

Materials

  • An AWS Account

    • S3 feature
  • Sample or HTML files to upload

Procedure

  • Log in to AWS

  • Search for and click the "S3" service

  • Click "Create bucket"

S3 Create Bucket Rules

General Configuration

  • Under "General configuration" give a name to the bucket. How naming works is, that the bucket must have a name no other bucket has. If a name has been given to a bucket but it has already been taken, that means someone else has created a bucket with that same name.

  • Every S3 bucket that is created can grant object ownership rights for either the creator or even other users who did not make the bucket. This is done by the Access Control Lists or short for ACLs. Disabling ACLs, means, all objects or files in the bucket are owned by the creator. Enabling ACLs means objects can be owned by other AWS accounts. If the owner only needs access to the bucket and the files, it is recommended to disable ACLs.

Object Ownership

Block Public Access settings for this bucket

  • More rules also set public access to the bucket. Enabling "Block all public access", ensures no ACLs and policies will affect the bucket to prevent other users from seeing the bucket. The "Block all public access" option can be unchecked to customize which of the four options can be checked or unchecked as well.

Bucket Versioning

  • Bucket versioning saves the previous copies or versions of the bucket and its files to be restored if needed.

Default Encryption

  • When every bucket is made, a server-side encryption option must be chosen to protect the objects that are in the object. Bucket keys are an option to be enabled as well.

  • Afterward, create the bucket

Hosting a Website

  • Click the Properties tab

  • In the Properties tab, scroll to the bottom of the page where it says "Static website hosting". For every new bucket that is created, "Static website hosting" is disabled. To enable it, click "Edit".

  • After clicking "Edit", there is the option to "Enable" it. This also gives an option to choose how to host the website. Select "Host a static website".

  • s3 buckets can only read HTML files to host a website. Under "Index document", it wants to know the name of the HTML file it must read to display the website's home page. If there is an error that prevents the bucket from displaying the homepage, under "Error document - optional" can be filled out to display another HTML page when there is a problem. Any name can be given to the HTML pages, as long it has the .html extension and the path of the file is stated correctly for the bucket to read to it. In this demonstration, both the default names for the html files "index.html" and "error.html" will be used to display the homepage and error respectively.

index.html file

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Sample Website</title>
    </head>

    <style>
        sentence {
            font-family:Arial;
            font-size: 24px;
        }
    </style>

    <body>
        <sentence> This is the homepage </sentence>
    </body>   

</html>

error.html file

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>An Error has Occurred</title>
    </head>

    <style>
        sentence {
            font-family:Arial;
            font-size: 24px;
        }
    </style>

    <body>
        <sentence> An error has occurred from displaying the homepage </sentence>
    </body>   

</html>
  • Once finished, click "Save Changes"

  • After enabling static website hosting, the bucket generates a link in the availability zone.

  • When clicking the link, an error occurs since the html files were specified but no HTML files were uploaded to the bucket yet and there are a few more modifications to make to view those files as well.

Making Configurations to View the Files in a S3 Bucket

  • To upload the files, go to the "Objects" tab

  • Click "Upload"

  • Click "Add files" to upload the HTML files

  • Once finished, click "Upload" and receive a confirmation if the files uploaded successfully

Disabling "Edit Block public access (bucket settings)"

  • For everyone to view the files in the bucket, "Block all public access" has to be unchecked.

  • In "Object Ownership", ACLs also have to be enabled and the files have to be made public using ACL

Editing Object Ownership

Make public using ACL

Afterward, the HTML pages can be accessed

Source Code

https://github.com/AndrewDass1/TUTORIALS/tree/main/AWS/S3/Use%20s3%20and%20Enable%20Static%20Hosting