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. In that case you need to add the redirection from the App level. If you want to do the redirection from outside the application, this should be a good approach.
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.
Cool. Relax.
Check below links:
1. How to give access only to a folder inside s3 bucket for an AWS IAM user?
2. Simple way to migrate s3 buckets across AWS accounts
that is not working on aws lightsail
Please keep in mind that this will only work for http, for https redirects you will need to setup a cloudfront distribution between the route and the S3 bucket.