0

So I run a service where a user can create a site and they get their own subdomain. So if a user has site a-site-name their subdomain will be a-site-name.domain.com. Some of the users want to be able to have their own domains instead of the subdomain on my domain. I know I should be able to do this with a CNAME record in DNS (so sub.the-users-domain.com resolves to a-site-name.domain.com). However when I try to do this, I get a 403 from Cloudfront.

To describe my setup:

  • Files are served by AWS Cloudfront using an S3 bucket as the origin point.
  • Each site a-site-name is stored in a folder in the S3 bucket of the same name.
  • I have a Lambda@Edge function running so that whenever a request is made to a-site-name.domain.com/whatever-resource (wildcard subdomains) it actually resolves to and grabs data from distribution-id.cloudfront.net/a-site-name/whatever-resource.

I'm guessing the fact that I'm getting a 403 has to do with the configuration of my Cloudfront deployment or with that Lambda@Edge function. Does anyone have any ideas as to how to change the configuration so that people can just use a CNAME record to use their own domains? I'm lost to be honest.

TomLisankie
  • 101
  • 1
  • Cloudfront needs to know which S3 bucket `sub.the-users-domain.com` points to. Setting a `CNAME` does not tell it that. – tater Aug 29 '20 at 10:30
  • Suspect you will need to write a lambda script to create the bucket, the domain, and glue everything together. – Tim Aug 29 '20 at 20:45

0 Answers0