AWS/Azure/OpenShift Version Control System (VSC)

Hosting Static Website and Versioning on AWS S3

s3versioning

Static websites can be defined as a type of website with a fixed display with the same content for every visitor to the website. This website is written in HTML and also prebuilt with CSS and JavaScript and uses a server-side rendering of these same files to every user. The word “static” means it does not change it remains the same for everyone as it is been loaded into the web browser for users to see. In a static website, you do not need to log in or perform some actions that are dynamic in nature. Versioning is one process that is very critical to any agile environment where application upgrade and maintenance are part of the software development life cycle. Versioning is an important process because user’s need specific information about the application version currently deployed to their environment and also the upgrade versions available for installation or deployment. You may also want a guide on how to create IAM users and setting policies for access to your static website by reading this Creating IAM Users, Adding MFA and Policies on AWS

Setting up your AWS Account
- Create an account via https://portal.aws.amazon.com/billing/signup
image-24
Sign Up Page

Log in to the AWS management console: https://signin.aws.amazon.com/

image-25
Sign in as Root User

After you have successfully created an AWS account and logged in, then navigate to S3 under the services→storage option. The next step is to create an S3 Bucket name.

image-26
Selecting S3 as storage

Please note that the bucket name must be unique across all AWS account and must not contain spaces or uppercase letters. 

If you want to know how to create an S3 bucket read this guide How to Deploy an Angular App to AWS S3. A step-by-step process on how to create an S3 bucket is covered in this guide.

Our S3 bucket name is techdirectarchivestaticwebsite as the image below shows:

  1. Click on the bucket name you created on your own AWS account but in our case we will click on techdirectarchivestaticwebsite.
image-27
Bucket List

2. Click on the Upload button to upload your static website files from your local system.

image-28
Uploading Page

3. You can drag and drop files and folders you want to upload from the location you have your static website files or choose Add files or Add folders from the same location.

image-29
Uploading Page

4. Copying the static website files from a location on my computer

image-30
Local System with deployment files

The below image shows the files that will be moved from my computer:

image-31

5. Click on the Upload button to start uploading the files

image-32
Uploading of Files

6. The uploading status for your files will display and when completed you the status will change.

image-33
Upload Status Page

7. Now that the whole files have been uploaded successfully, make sure you check the Permission tab and in the permission overview change the access to Public. You can edit the bucket policy with the below policy below but make sure you change the Resource name to yours

image-34
Bucket Policy

But note that it is recommended that you block all public access to your buckets, we are only using this Public access to explain in this guide.

image-35
Permission Overview Page

8. In the Properties tab scroll down to the Static website hosting section and click on the Edit button. In the Static website options select Enable and in the Hosting type options select Host a static website.

image-36
Static Web Configuration

9. In the Index document section enter index.html while in the Error document enter error.html.

image-37
Index and Error document

10. To make the files accessible to the public you need to go to the objects tab and select all the files and choose Make public as the action.

image-38
Objects details

11. Click on the Make public button.

image-39
Making Files Public

Files status now public

image-40
Public Status

12. Go to the Properties tab and scroll down to the Static website hosting section, click the URL.

image-41
Static Website Hosting Details

13. Congratulations: here come our static website

image-42
Our Static Website

Versioning our deployment files

When you activate S3 Versioning it will help keep multiple versions of an object in one bucket with different version id. It will also help to restore objects that are accidentally deleted or overwritten.

Let’s take for example if an object is deleted, instead of removing it permanently, Amazon S3 will insert a delete marker. Follow these short steps to version your deployment to AWS S3.

14. Under the Properties tab scroll down to the Bucket Versioning section and click the Edit button and select Enable.

image-43
Bucket Versioning

Now since Bucket Versioning is now enabled on our S3 Bucket let’s try and make some little adjustments to our uploaded files locally and try to upload again and let’s see the effect.

15. In this instance we will be making some little adjustments to the index.html file and re-upload it to our S3. After uploading it you will see a new version id assigned to it while the older version (circled index.html) will now be linked to the new version above it as we have in the image below.

image-44
Website Files

Now our static website has now picked the new changed and the image below shows the newly deployed version of our static website.

image-45
Static Website Version 2

If you want to copy any of the versions you can just go to the action drop-down and select Download.

16. Another thing we will be checking is when deleting an object or file on S3 that the versioning is enabled. For instance, we will try and delete the delete.txt file in the image below. Click on the Delete button.

image-46
Deleted File

The below image will be displayed after clicking the Delete button. In the Delete objects section enter delete in the text input field.

image-47
Delete Objects Overview

17. After deletion you will notice that a Delete marker will be placed on the deleted file. If you need the deleted file back you only need to select the deleted file with the Delete marker and click the Delete button.

image-48
Delete Marker

When you recheck the deleted files you will see that it has been returned back to the previous location.

If you have followed this guide to this end you will be able to host a static website and do versioning for your deployed files.

I hope you found this blog post on how to host static websites and versioning on AWS S3 very interesting and helpful. In case you have any questions do not hesitate to ask in the comment section.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Kindly subscribe to TechDirectArchive
This is default text for notification bar