Member-only story
Subdomains with CloudFront
In most use cases we use AWS CloudFront with a single domain where the origin can be either an S3 bicket, API Gateway, Application Load balancer, or any other origins that support CloudFront. But there may be a use case where we will need to support subdomains using the same distribution as well like the following.
Main Domain — abc.com
Customer with site name site 1 — site1.abc.com
Customer with site name site 2 — site2.abc.com
I think you now get the idea of this use case. In this post, I will explain how this can be achieved using a single CloudFront distribution on AWS.
So before starting we should go ahead and create a cloudfront distribution with the relevant origin with it. I will not explain the steps on doing it since it will change depending on the origin.
After creating the distribution the first step would be to create a custom SSL certificate which would support our subdomains as well.
Create a Custom SSL certificate
Go to AWS Certificate Manager and click on Request
Next, click on Request public certificate.
Next, add the domain names that we are going to use for this SSL certificate. Make sure to add a wildcard domain to support the…