Avoiding the “CNAME Already Exists” Error When Attaching a Domain

Conditions

This error occurs when the domain you are attempting to attach to Shifter is already registered with an existing CloudFront instance.

Reason for the Error

Shifter uses CloudFront as its CDN, and in accordance with AWS specifications, a domain name must be unique across CloudFront. Therefore, an error occurs if you try to configure the same domain on another CloudFront distribution.

Use custom URLs by adding alternate domain names (CNAMEs)

Workarounds

You can avoid this error by using one of the following methods.

Workaround A: Attach a domain different from the existing one to Shifter and use it for operations

You can avoid the error by using a domain different from the existing one.

  • Example: For the existing domain example.com, use the domain shifter.example.com for Shifter.

Workaround B: Detach or delete the domain from the existing CloudFront instance, then attach it to Shifter

  1. Remove the target domain from the existing CloudFront instance.
  2. Update the DNS records to point to the Shifter site.
  3. After making the changes, attach the domain to the Shifter site.
  4. Generate the Shifter site.

Note: Since traffic to the domain may temporarily return a 403 Forbidden error once it is removed from CloudFront, we recommend performing this during off-peak hours.

Flowchart for Resolving the CloudFront CNAMEAlreadyExists Error (Summer 2021 Edition) This article is easy to understand.

Workaround C: Apply the domain only to Shifter artifacts (requires shifter-cli).

By applying a custom domain only to Shifter artifacts—rather than to Shifter as a whole— you can avoid the “CNAME Already Exists” error. However, if you use this method, you’ll need to configure a reverse proxy or similar to properly forward traffic from external servers.

Steps to Follow:

  1. Install shifter-cli.
  2. Run the following command to attach a custom domain.
$ shifter attach --username USERNAME --password PASSWORD --site-id YOUR-SITE-ID --domain DOMAIN --no-shifter-cdn

Reference: