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.comandexample2.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. ACM has a default quota of 10 domains, but you can request up to 100 domain names.
    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 CloudFront Functions or Lambda@Edge to route to an origin based on the Host header. For more information, see Choose between CloudFront Functions and Lambda@Edge.

Related information

Distribution settings reference

Using custom URLs by adding alternate domain names (CNAMEs)

AWS OFFICIAL
AWS OFFICIALUpdated 2 months ago
6 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

replied 2 years ago

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

profile pictureAWS
MODERATOR
replied 2 years ago

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

replied 2 years 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.

replied 2 years ago

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

profile pictureAWS
EXPERT
replied 2 years ago

I have multiple domains like abc.com, dbe.com, fgi.com and many more in single distribution and this all domains have same paths like abc.com/product/polo, dbe.com/product/polo, fgi.com/product/polo and all the other domains. I want to store cache for each domain by separate cache entry. is it possible to do?

replied 5 months ago