no-www snippets

How to configure a no-www redirection on Amazon AWS (S3 and Cloudfront)

Tagged no-www, amazon, s3, cloudfront  Languages bash

How do you configure a site hosted on Amazon AWS, e.g. a static website, to redirect from "www" to the "no-www" domain (aka "naked domain")? The tool for the job is the AWS CLI.

For example, this creates a redirection from to for a bucket named

aws s3api put-bucket-website --bucket --website-configuration '{
    "RedirectAllRequestsTo": {
        "HostName": ""

Use this command to check that the configuration is set properly:

aws s3api get-bucket-website --bucket