How can I serve multiple domains from a CloudFront distribution over HTTPS?

2 minute read
1

I want to serve multiple domains from an Amazon CloudFront distribution over HTTPS.

Resolution

To serve multiple domains from CloudFront over HTTPS, add the following values to your distribution settings:

  • Enter all domain names in the Alternate Domain Names (CNAMEs) field. For example, to use the domain names example1.com and example2.com, enter both domain names in Alternate Domain Names (CNAMEs).
    Note: Choose Add item to add each domain name on a new line.
  • Add your SSL certificate that covers all the domain names. You can add a certificate that's requested with AWS Certificate Manager (ACM). Or, you can add a certificate that's imported to either AWS Identity and Access Management (IAM) or ACM.
    Note: It's a best practice to import your certificate to ACM. However, you can also import your certificate in the IAM certificate store.

For each the domain name, configure your DNS service so that the alternate domain names route traffic to the CloudFront domain name for your distribution. For example, configure example1.com and example2.com to route traffic to d111111abcdef8.cloudfront.net.

Note: You can't use CloudFront to route to a specific origin based on the alternate domain name. CloudFront natively supports routing to a specific origin based only on the path pattern. However, you can use Lambda@Edge to route to an origin based on the Host header. For more information, see Dynamically route viewer requests to any origin using Lambda@Edge.

Related information

Values that you specify when you create or update a distribution

Using custom URLs by adding alternate domain names (CNAMEs)

AWS OFFICIAL
AWS OFFICIALUpdated a year ago
5 Comments

can i use Alternate Domain Names to redirect it to different origin ? for example:

dev.example.com > point to X s3 bucket (using origin X)
qa.example.com > point to Y s3 bucket ( using origin Y)

under the same distribution

Hany
replied a year ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied a year ago

Hi, I am interested in the question by Hany too. May I know is it already updated in Knowledge Center article?

LaiYH
replied a year ago

The presented solution limits the number of domains to the max that a certificate can contain (10 per AWS cert by default). I have a situation where I may have thousands of domains all pointing to a multi tenant system. Can CloudFront be used in such a situation? without creating many certs and CloudFront distros.

devlop
replied 10 months ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied 10 months ago