I'm trying to implement a "proxy" to multiple websites using lambda@edge on AWS Cloudfront.
My setup is roughly:
DNS: *.domain.com -> some_uuid.cloudfront.net (Cloudfront distribution)
Cloudfront: some_uuid.cloudfront.net -> s3 bucket origin
s3 bucket: websites/ (a folder that contains multiple websites)
lambda@edge function: defined as origin-request
My lambda@edge function is quite simple:
check if the website resource exists in the s3 bucket.
if it does, change the request uri to the resource s3 url.
if not, send a request to a backend server to render the resource, store on s3 and return it.
I'm having trouble getting the origin domain of the website. For example, if I try to access "my_website.domain.com" - in my lambda function i don't have this domain info from the request.
I think I can implement another lambda@edge function as viewer request to pass the domain as a header, but if I can, I prefer to avoid that.
Is there any other solution?
Thanks