This is a simple workaround to redirect all non www request to www domain, from AWS Route 53. In this case your, I am considering that, your APP/Site is directly connecting from some ELB to direct App/Web port. No web-servers running on server to do the redirection.
If you have any webservers running on the host server as a proxy, we can simply create redirection rule from there. Like, Apache or Nginx on host server as proxy. In those case, redirect rules help you.
In this scenario, our www domain is directly pointing from Route 53 to an ELB, then ELB to host server directly using port. So we have to redirect the non-www traffic to www domain from the Route 53 level.
How we can redirect non-www traffic to www domain from Route 53?
We can simply done this by the help of an s3 bucket. You must have privilege to create s3 bucket and Route 53 edit access. Here I am explaining the steps with some screensshots. Please see the steps pasted below:
Step 1. Create an s3 bucket.
This is the first step. You need to create an s3 bucket with the domain name which you want to redirect to www. To create s3 bucket, log onto AWS console, services -> Amazon S3 -> Create bucket -> Create a bucket with non www domain name.
Step 2. Make the bucket as a Static website hosting with redirect.
For this, go to bucket properties, choose Static website hosting with redirect requests.
Add the www redirect there and save it. That’s it.
Step 3. Edit AWS Route 53 entry for non www domain.
Go to AWS Route 53, select hosted domain, select the zone entry. From the right side, chose the setting as:
A – IPv4 Address -> Alias Yes -> Alias Target (Select the s3 bucket end point from the drop down).
Step 4. Save record set.
That’s it!! Wait for the DNS propagation delay. You will be all set after the DNS propagation.
Check below links: