Skip to content

to fuse 2 websites in one domain using lambda@edge and cloudfront

Notifications You must be signed in to change notification settings

Gokaysim/site_swapper

Repository files navigation

site_swapper

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


Setup

Blog Site

  • 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

React Site

  • A ReactJs site is uploaded to S3.
  • Static website property of S3 is enabled.

CloudFront

  • A cloud front setup with 2 origin and 2(or more) behaviours is configured.
  • First(precedence 0) behaviour should catch /blog* and should forward to WordPress site.
  • Second(precedence 1) behaviour should catch all * (default). And it should forward it to S3.
  • Lambda@edge

    • 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*

    About

    to fuse 2 websites in one domain using lambda@edge and cloudfront

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published