eolas/DevOps/AWS/AWS_Lambda/Lambda_examples.md
2023-04-08 18:55:52 +01:00

670 B

categories tags
DevOps
AWS
aws-lambda
backend

AWS Lambda examples

Reconstruct CloudFront URLs

exports.handler = (event, context, callback) => {
  // Extract the request from the CloudFront event that is sent to Lambda@Edge
  var request = event.Records[0].cf.request;

  // Extract the URI from the request
  var olduri = request.uri;

  // Match any '/' that occurs at the end of a URI. Replace it with a default index
  var newuri = olduri.replace(/\/$/, "/index.html");

  // Replace the received URI with the URI that includes the index page
  request.uri = newuri;

  // Return to CloudFront
  return callback(null, request);
};