0

I want to redirect cloud-front lambda@edge through redirect my s3 bucket signed url.

 exports.handler = async(event, context, callback) => {

    console.log(JSON.stringify(event));


    const request = event.Records[0].cf.request;

    let path = request.uri.substring(1);
    let bucket = "bucket name";
    const url = s3.getSignedUrl("getObject", {
        Bucket: bucket,
        Key: path,
        Expires: 20 * 60, //time to expire in seconds - 20 min
    });
    console.log(url);
    //here which code apply to redirect to signedurl s3
    callback(null, request); 
} 

I have private file in my s3 that bucket connected through cloud-front.

then we set lambda edge on

Event type: origin-request

but now i face issue. I don't know how to i redirect new generated signed request in s3 from lambda edge.

Sandip
  • 3
  • 3
  • //try 2 `var newURL = url.replace("https://" + request.origin.s3.domainName + "/", ""); request.uri = newURL; callback(null, request); ` – Sandip Feb 27 '21 at 08:16
  • //try 1 ` const response = { statusCode: 301, headers: { Location: url } }; console.log(JSON.stringify(response)); return response; ` – Sandip Feb 27 '21 at 08:19
  • Unless you explain why your tries don't work its difficult to help. Also AWS docs [explain](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html#lambda-examples-http-redirect) how to redirect. Have you tried that? If yes, why it does not work? Any error messages? – Marcin Feb 27 '21 at 09:07

0 Answers0