Overview:
In this Blog, we will deploy a static web using S3.
Creating a bucket:
Search for S3 in the search box.
From the right side click on Create bucket.
Give the bucket name. I will name it "static".
From the Object Ownership box check the ACLs enabled one.
Coming down uncheck the box "Block all public access". It will be checked by default.
Check the "I acknowledge that the current settings might result in this bucket and the objects within becoming public."
Coming down click on Create bucket.
Our bucket will be created.
Uploading a Simple Page in the Bucket:
Open the bucket created by us a few minutes ago.
My bucket name was "static".
Click on the Upload button.
Now choose Add files.
Choose any HTML file which you have.
I have created a simple page and the code for the page is:
<html> <body> <h1>This is my first containerized app using docker</h1> <img src="https://developers.redhat.com/sites/default/files/styles/article_feature/public/blog/2014/05/homepage-docker-logo.png?itok=zx0e-vcP" alt="docker" style="float: left; max-width: 700px;"> </body> </html>
After choosing the HTML file click on Upload from the bottom.
Our file is uploaded in the bucket.
Now come back and open the bucket again.
Now click on the Properties option.
Scroll down to the bottom at the end.
We will see if there will be a section for Static website hosting.
click on the Edit button.
Select the option "Enable" from the static website hosting.
Now in the index document give it a name. I will suggest giving the same name as the uploaded HTML file in the bucket.
I will give the name index.html.
Now from the bottom click on Save Changes. It is at the end.
Running the Web Page:
Open the uploaded file in the bucket.
Copy the Object URL from the Object Overview.
paste it in the browser and we will see our page is not running. It is showing up like this:
Now again go back to your Bucket and open the Permissions.
- In the "Block public access (bucket settings)" click on Edit.
Uncheck all these:
-
Click on Save Changes.
Now a box will appear type "confirm" and click on confirm.
Come back in the Permissions of the Bucket created by us.
Click Edit in the Bucket Policy.
paste this code in the Blank Space in the Policy.
{
2 "Version": "2012-10-17",
3 "Statement": [
4 {
5 "Sid": "AllowPubllicAccesstoObjects",
6 "Effect": "Allow",
7 "Principal": "*",
8 "Action": "s3:GetObject",
9 "Resource": "YOUR-BUCKET-NAME/*"
10 }
11 ]
12}
Just in the Resource give your bucket name. replace it.
Replace it with Bucket ARN. It is just above the Policy.
Make sure to keep /*" at the end.
Click on save changes from the bottom.
Refresh your page again it will run now.