Skip to content

wp-digital/aws-lambda-prerender

Repository files navigation

AWS Lambda Prerender

Description

AWS Lambda function for generating HTML for client-side rendered content.

WordPress

Initially this function was created to be used with WordPress via plugin AWS Lambda Prerender, so you just need to install plugin.

Basic usage (non WordPress)

Event JSON:

Name Type Description
type string Type of content, e.g. post or frontpage
id string Identifier, e.g. ID of Post from database.
url string URL for grabbing HTML.
variable string Name of global variable with rendered HTML to string.
selector string Selector of root element to grab. Not used for grabbing when variable set but always in use to detect page load.
return_url string Endpoint where result should be returned.
secret string Secret to be added to POST callback request.
version string Version of HTML.

Notes

  • Idea of variable is to use e.g. renderToString from React to render HTML otherwise element's HTML with selector will be used.
  • Secret is for authorization. In WordPress plugin this secret has 20 minutes live time (15 minutes is a maximum execution time of AWS Lambda function and 5 minutes of reserve).

Example:

{
  "type": "post",
  "id": 345,
  "url": "https://www.site.com/blog/hello-world/",
  "variable": "prerender",
  "selector": "#app",
  "return_url": "https://site.com/api/v1/prerender",
  "secret": "aQ3qnPPnDwhaB7pzI3Y0jQx*",
  "version": "381d3e8bfd139596baf7959fb85b084e"
}

Installation

  • Use this template from Github.
  • Create AWS Access Keys. You can follow this gist to create policy.
  • Add API Key & Secret with Region to Github Repository secrets into AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION variables.
  • Deploy function with Github Actions. dev branch will be deployed on push into prerender-dev-render function, production should be deployed manually through workflow_dispatch into prerender-production-render.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published