{"id":20484073,"url":"https://github.com/nuxy/lambda-js-prerender","last_synced_at":"2025-07-11T18:08:12.938Z","repository":{"id":200213379,"uuid":"705049394","full_name":"nuxy/lambda-js-prerender","owner":"nuxy","description":":twisted_rightwards_arrows: AWS CloudFront Lambda serverless JavaScript prerenderer.","archived":false,"fork":false,"pushed_at":"2024-03-22T18:22:46.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T04:25:48.405Z","etag":null,"topics":["aws-lambda","function","javascript","puppeteer","renderer","serverless"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuxy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-14T22:18:58.000Z","updated_at":"2024-03-20T00:20:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"8450eba0-c7dc-4132-b4b6-ce6f79780a5f","html_url":"https://github.com/nuxy/lambda-js-prerender","commit_stats":null,"previous_names":["nuxy/lambda-js-prerender"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxy%2Flambda-js-prerender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxy%2Flambda-js-prerender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxy%2Flambda-js-prerender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxy%2Flambda-js-prerender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuxy","download_url":"https://codeload.github.com/nuxy/lambda-js-prerender/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242058218,"owners_count":20065066,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","function","javascript","puppeteer","renderer","serverless"],"created_at":"2024-11-15T16:19:47.901Z","updated_at":"2025-03-05T16:18:27.822Z","avatar_url":"https://github.com/nuxy.png","language":"JavaScript","readme":"# lambda-js-prerender\n\n![git Version](https://img.shields.io/github/package-json/v/nuxy/lambda-js-prerender?style=flat-square\u0026svg=true\u0026label=git+package) [![Build Status](https://img.shields.io/github/actions/workflow/status/nuxy/lambda-js-prerender/.github%2Fworkflows%2Fci.yml)](https://github.com/nuxy/lambda-js-prerender/actions) [![](https://img.shields.io/github/v/release/nuxy/lambda-js-prerender)](https://github.com/nuxy/lambda-js-prerender/releases)\n\nAWS [CloudFront Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) serverless JavaScript [prerenderer](https://github.com/prerender/prerender).\n\n## Features\n\n- Ability to prerender SPA (Single-page application) pages for SEO indexing.\n- Ability to create screenshots of dynamically generated pages for testing.\n- Serverless function, scales [on a tight budget](https://s3.amazonaws.com/lambda-tools/pricing-calculator.html).\n- Can be set-up easily (in minutes).\n\n## Dependencies\n\n- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)\n- [Docker](https://www.docker.com/get-started)\n- [Node.js](https://nodejs.org)\n\n### Get the [Chromium](https://opensource.google/projects/chromium) binary\n\n    $ wget -c https://github.com/nuxy/chromium-lambda-build/releases/download/0.0.2/headless_shell.tar.gz -O - | tar -xz\n\n## Deploying to AWS\n\n    $ ./deploy --profile \u003cAWS credentials profile\u003e\n\nThe following operations are orchestrated by AWS [CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) during execution:\n\n- Docker container image is created and uploaded to AWS [Elastic Container Registry](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html).\n- AWS [Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) function is created with a configured [Function URL](https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html) endpoint.\n- AWS [CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) distribution is created using the new function as origin.\n- Network routing occurs thereby exposing your Lambda function URL\n\n## Invoking the service\n\n### Command-line\n\n```sh\ncurl -X 'POST' \\\n  'https://\u003curl-id\u003e.lambda-url.\u003cregion\u003e.on.aws' \\\n  -H 'Accept: text/html' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"url\": \"\u003csite-url\u003e\", \"image\": \u003cboolean\u003e}'\n```\n\n### In Node.js\n\n#### AWS SDK for JavaScript v3\n\n```javascript\nconst {LambdaClient, InvokeCommand} = require('@aws-sdk/client-lambda');\n\nconst client = new LambdaClient({region: '\u003cregion\u003e'});\n\nconst params = {\n  FunctionName: 'PrerenderApi',\n  InvocationType: 'RequestResponse',\n  LogType: 'Tail',\n  Payload: JSON.stringify({\n    url: '\u003csite-url\u003e',\n    image: \u003cboolean\u003e\n  })\n};\n\nconst command = new InvokeCommand(params);\n\ntry {\n  const {PayLoad} = await client.send(command);\n\n  console.log(Payload?.body));\n\n} catch (err) {\n  console.warn(err.message);\n  throw err;\n}\n```\n\n#### AWS SDK for JavaScript v2\n\n```javascript\nconst AWS = require('aws-sdk');\n\nconst client = new AWS.Lambda({region: '\u003cregion\u003e'});\n\nconst params = {\n  FunctionName: 'PrerenderApi',\n  InvocationType: 'RequestResponse',\n  LogType: 'Tail',\n  Payload: JSON.stringify({\n    url: '\u003csite-url\u003e',\n    image: \u003cboolean\u003e\n  })\n};\n\nclient.invoke(params).promise()\n  .then(function({Payload}) {\n    console.log(Payload?.body));\n  })\n  .catch(function(err) {\n    console.warn(err.message);\n    throw err;\n  });\n```\n\n## Environment variables\n\nThe following function environment overrides can be configured in the SAM [template](https://github.com/nuxy/human-face-detection/blob/master/template.yaml#L23) file:\n\n| Variable name      | Description          | Default value |\n|--------------------|----------------------|---------------|\n| `PRERENDER_DEBUG`  | Enable verbose logging to [CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) group | false |\n|`PRERENDER_TIMEOUT` | Execution timeout in seconds | 60 |\n\n## AWS requirements\n\nIn order to successfully deploy your application you must have [set-up your AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/gs-cli.html) and have [created an IAM user](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html) with the following [policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage.html):\n\n- [IAMFullAccess](https://console.aws.amazon.com/iam/home#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FIAMFullAccess)\n- [CloudFrontFullAccess](https://console.aws.amazon.com/iam/home#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FCloudFrontFullAccess)\n- [AWSCloudFormationFullAccess](https://console.aws.amazon.com/iam/home#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FAWSCloudFormationFullAccess)\n- [AWSLambda_FullAccess](https://console.aws.amazon.com/iam/home#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FAWSLambda_FullAccess)\n- [AmazonEC2ContainerRegistryFullAccess](https://us-east-1.console.aws.amazon.com/iam/home#/policies/arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess)\n\nWARNING: The policies above are provided to ensure a successful application deployment.  It is recommended that you adjust these policies to meet the security requirements of your Lambda application.  They should NOT be used in a Production environment.\n\n## Developers\n\n### CLI options\n\nRun [ESLint](https://eslint.org/) on project sources:\n\n    $ npm run lint\n\nGenerate [Swagger](https://swagger.io) OpenAPI definitions:\n\n    $ npm run genapi\n\nRun [Mocha](https://mochajs.org) unit tests:\n\n    $ npm run test\n\n## Performance\n\nRunning in Lambda there is overhead that occurs ([cold start](https://docs.aws.amazon.com/lambda/latest/operatorguide/execution-environments.html)) when the environment is first launched.  This overhead does not include [headless shell](https://github.com/nuxy/chromium-lambda-build) initialization which creates its own latency.  Due to this, you can expect a longer response time for the first request.  As long as there is an active Lambda handler (hot start) all subsequent requests will not incurr this overhead.\n\n## References\n\n- [Setting IAM Permissions and Roles](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-permissions.html)\n- [Scaling and concurrency in Lambda](https://docs.aws.amazon.com/lambda/latest/operatorguide/scaling-concurrency.html)\n- [Lambda quotas](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html)\n- [AWS SDK for JavaScript](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/index.html)\n- [chromium-lambda-build](https://github.com/nuxy/chromium-lambda-build)\n- [content_switches.cc](https://source.chromium.org/chromium/chromium/src/+/main:content/public/common/content_switches.cc?q=kDisableGpu\u0026ss=chromium)\n\n## Versioning\n\nThis package is maintained under the [Semantic Versioning](https://semver.org) guidelines.\n\n## License and Warranty\n\nThis package is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.\n\n_lambda-js-prerender_ is provided under the terms of the [MIT license](http://www.opensource.org/licenses/mit-license.php)\n\n[AWS](https://aws.amazon.com) is a registered trademark of Amazon Web Services, Inc.\n\n## Author\n\n[Marc S. Brooks](https://github.com/nuxy)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxy%2Flambda-js-prerender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuxy%2Flambda-js-prerender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxy%2Flambda-js-prerender/lists"}