This codebase can be used to serve to 2 website on same domain via AWS CloudFront and lambda@edge function.
In my case I needed to serve a ReactJS and wordpress site in same domain for SEO purposes. I explain setup based on my use case and technology stack. But other technologies or even more than 2 sites can be served under one domain
- WordPress site is deployed to AWS EC2.
- A load balancer is deployed in front of EC2
- EC2 inbound rules are modified in order to restrict access.
- robots.txt with disallow is placed under root directory. In order to prevent google from indexing load balancer as another site
- A ReactJs site is uploaded to S3.
- Static website property of S3 is enabled.
- The code is uploaded to a lambda function with 128mb memory, 5 seconds timeout and without any env or layers
-
Trigger of lambda function should be set as CloudFront as below configuration:
- EventType: origin-request
- Include Body: checked
- Path Patern: blog*