Skip to content

SERA integration on CloudFront

Kindly follow the below steps to setup the routing of bot traffic to SERA.

Prerequisites

  1. Your origin server does not need host header to manage routing.
    This is because while forwarding bot requests to SERA, you need to send the SERA's host header instead of your domain's header on the request (to avoid SAN error).
    For this, you need to attach AllViewerExceptHostHeader as Origin request policy to the respective behavior that'll be forwarding the bot request. In this case, if your origin is expecting host header to route the request, it will fail.

    1. In case, this is not possible, you can check with N7 team for _acme_challenge CNAME record to add at your end.
      With this, we will be able to generate SSL certificate for your domain at our end - which will avoid SAN error.

Steps

  1. Creating a function

    1. Open Cloudfront Dashboard, and select Functions menu on the left side
      Step

    2. Click on Create function
      Step

    3. Fill the details as shown below :
      Name:

      n7-sera-routing
      
      In Runtime, select Cloudfront-js-2.0
      And then Click on Create function
      Step

    4. Select Build tab
      Copy the code from this js file, and paste it in the textarea.
      Put the SERA token shared with you in SERA_TOKEN variable value
      Keep required value uncommented for BOTS variable based on testing/live phase
      Click on Save
      Step

    5. Select Test tab
      Leave everything unchanged, and click on Test function. You should then see a success message.
      Step

    6. Select Publish tab
      Click on Publish function
      Step

  2. Associating the function to Behavior

    1. Select Distributions menu on Left
      Step

    2. Click on the respective distribution from the list OR create a new one for URL pattern to be sent to SERA
      Select Behaviors tab
      Step

    3. Select respective behavior, and Edit it
      Step

    4. Set Origin request policy to AllViewerExceptHostHeader. This is to retain SERA endpoint host header when Cloudfront proxies request to it to avoid SAN errors.
      Step

    5. Go to bottom Function associations section at bottom
      Step

    6. In Viewer request section, select Cloudfront Functions as Function type
      Step

    7. Select the created function (n7-sera-routing) in Function ARN/Name dropdown
      Step

    8. Save

  3. Testing and Refinement

    • Keep refining the logic by adjusting user-agent list, and SERA exclusion-patterns as needed.

    • Whitelist SERA requests at your origin to avoid any issues with indexing. Details are here

    • Test thoroughly:

      • WPT and GTMetrix will automatically receive the response from SERA due to the routing rule set above.

        • Steps to validate page using WPT
      • To check the SERA rendered page on browser, you can use DevTools > Network conditions facility, or some browser extension (like Simple modify headers) to manipulate the browser user-agent.
        If in testing phase, use these user-agent values:
        For desktop:

        n7TestUserAgent
        
        For mobile:
        n7TestUserAgent; Android
        
        If SERA is live, you can use these actual bot user-agent values:
        For desktop:
        Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +<http://www.google.com/bot.html)> Chrome/W.X.Y.Z Safari/537.36
        
        For mobile:
        Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +<http://www.google.com/bot.html)>
        

    • On go-live day, set the user-agent condition regex to actual bot user-agent values. Additionally, ensure that your condition is case-insensitive.

    • After go-live, in any dashboards created for monitoring the "actual user traffic" e.g. Google analytics, exclude the requests with user-agent string containing word "Nitrogen SERA" to get correct understanding about user-traffic.