Lambda@Edge function to replace metas in S3 bucket
✓ Published0🌍 Public
LLucienPerouze
Last edited Apr 29, 2018
Created on Apr 29, 2018
This example shows how to programmatically replace meta tags in an HTML page by combining a static index.html file with a dynamic API response. The Lambda@Edge handler intercepts incoming CloudFront requests, and for URIs without a file extension, it fetches both the base HTML and a JSON object of metas from a remote HTTPS API in parallel using `Promise.all` and `https.get`. It then substitutes `%meta%` tokens in the HTML for each key from the JSON via regular expressions. Requests with file extensions pass through unchanged, while errors are caught and returned as a server-side rendering error message in the response body.
AI-generated description