AWS Lambda function for generating HTML for client-side rendered content.
Initially this function was created to be used with WordPress via plugin AWS Lambda Prerender, so you just need to install plugin.
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. |
- Idea of
variable
is to use e.g. renderToString from React to render HTML otherwise element's HTML withselector
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"
}
- 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
andAWS_REGION
variables. - Deploy function with Github Actions.
dev
branch will be deployed on push into prerender-dev-render function, production should be deployed manually throughworkflow_dispatch
into prerender-production-render.