I think is the way AWS have designed this and that's it : Check this
I have this done for my company's website and it works great!
Create an S3 bucket and configure it to host a website
Amazon S3 lets you store and retrieve your data from anywhere on the
internet. To organize your data, you create buckets and upload your
data to the buckets by using the AWS Management Console. You can use
S3 to host a static website in a bucket. The following procedure
explains how to create a bucket and configure it for website hosting.
To create an S3 bucket and configure it to host a website
- Open the Amazon S3 console at https://console.aws.amazon.com/s3/.
- Choose Create bucket.
- Enter the following values:
- Bucket name - Enter the name of your domain, such as example.com.
- Region - Choose the region closest to most of your users.
- Make note of the region that you choose; you'll need this information later in the process.
- Choose Next.
- On the Configure options page, choose Next to accept the default values.
- On the Set permissions page, uncheck the Block all public access check box, and choose Next.
Note
The console displays a message about public access to the bucket. Later in this procedure, you add a bucket policy that limits access to the bucket.
- On the Review page, choose Create bucket.
- On the list of S3 buckets, choose the name of the bucket that you just created.
- Choose the Properties tab.
- Choose Static website hosting.
- Choose Use this bucket to host a website.
- For Index document, enter the name of the file that contains the main page for your website.
Note
You'll create an HTML file and upload it to your bucket later in the process.
- Choose Save.
- Choose the Permissions tab.
- Choose Bucket policy.
Copy the following bucket policy and paste it into a text editor. This policy grants everyone on the internet ("Principal":"*")
permission to get the files ("Action":["s3:GetObject"])
in the S3 bucket that is associated with your domain name ("arn:aws:s3:::your-domain-name/*")
:
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal":"*",
"Action":[
"s3:GetObject"
],
"Resource":[
"arn:aws:s3:::your-domain-name/*"
]
}]
}
- In the bucket policy, replace the value your-domain-name with the name of your domain, such as example.com. This value must match the name of the bucket.
- Choose Save.
Create another S3 Bucket, for www.your-domain-name
In the preceding procedure, you created a bucket for your domain name, such as example.com. This allows your users to access your website by using your domain name, such as example.com.
If you also want your users to be able to use www.your-domain-name, such as www.example.com, to access your sample website, you create a second S3 bucket. You then configure the second bucket to route traffic to the first bucket.
Note
Websites typically redirect your-domain-name to www.your-domain-name, for example, from example.com to www.example.com. Because of the way S3 works, you must set up the redirection in the opposite direction, from www.example.com to example.com.
To create an S3 bucket for www.your-domain-name
- Choose Create bucket.
- Enter the following values:
- Bucket name - Enter www.your-domain-name. For example, if you registered the domain name example.com, enter www.example.com.
- Region -Choose the same region that you created the first bucket in.
- Choose Next.
- On the Configure options page, choose Next to accept the default values.
- On the Set permissions page, choose Next to accept the default values.
- On the Review page, choose Create bucket.
- n the list of S3 buckets, choose the name of the bucket that you just created.
- Choose the Properties tab.
- Choose Static website hosting.
- Choose Redirect requests.
- Enter the following values:
- Target bucket or domain
- Enter the name of the bucket that you want to redirect requests to. This is the name of the bucket that you created in the procedure To create an S3 bucket and configure it to host a website.
- Protocol - Enter http. You're redirecting requests to an S3 bucket that is configured as a website endpoint, and Amazon S3 doesn't support HTTPS connections for website endpoints.
- Choose Save.