Skip to content

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:

NameTypeDescription
typestringType of content, e.g. post or frontpage
idstringIdentifier, e.g. ID of Post from database.
urlstringURL for grabbing HTML.
variablestringName of global variable with rendered HTML to string.
selectorstringSelector of root element to grab. Not used for grabbing when variable set but always in use to detect page load.
return_urlstringEndpoint where result should be returned.
secretstringSecret to be added to POST callback request.
versionstringVersion 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

0 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages