Redirecting www Domain to non-www using 0 code at AWS

Let us say that you do not want to www. subdomain for your website and want to have a 301 redirect to non-www version. There are millions of way of doing that, but luckily you are on AWS, you serve your domain via Route53. You can then keep your application configuration clean from this redirect logic via native AWS tools: You can leverage S3 and Cloudfront to accomplish this goal.

Following the infrastructure as code principle, I do not paste here complicated steps or screenshots on AWS console, but here I share a Cloudformation template that will set up everything for you:

You should just install this Cloudformation template to us-east-1 region (It will check where it is installed and fail if you install to another region.) The only parameters that it needs are domain name without www and Hosted Zone Id in Route53 to create necessary record.

This template will create a SSL certificate for you via Amazon Certificate Manager, create a S3 bucket with required redirection logic, a Cloudfront distribution to wrap all of them and you will have your serverless redirection ready in minutes.

Note that for certificate creation, AWS will send an confirmation E-Mail to your domain’s registered E-Mail address and Cloudformation will not be installed before you approve the E-Mail. Also as you might already know, Cloudfront updates take time so please give this template some time to be fully installed.

Happy cloud computing!

Cagatay Gurturk’s Blog

My personal blog where I share stuff about IT, mostly about…

Çağatay Gürtürk

Written by

Software Development Manager @ebay, and Founder of @instelacom. Author of Building Serverless Architectures and AWS Certified Solutions Architect.

Cagatay Gurturk’s Blog

My personal blog where I share stuff about IT, mostly about Cloud computing.

Çağatay Gürtürk

Written by

Software Development Manager @ebay, and Founder of @instelacom. Author of Building Serverless Architectures and AWS Certified Solutions Architect.

Cagatay Gurturk’s Blog

My personal blog where I share stuff about IT, mostly about Cloud computing.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store