I have done redirection using lambda@edge in Cloudfront.
How to hit the origin back at certain conditions from lambda@edge ??
Is that possible ??
In a request trigger, if you want to return control to CloudFront and allow it to continue processing the request normally, you invoke the callback with the original request and return.
return callback(null, event.Records[0].cf.request);
If you captured the request object earlier in the handler...
const request = event.Records[0].cf.request;
...then you can just return that copy:
return callback(null, request);
Note that you can invoke callback()
without return
, but using the style shown above ensures that the handler function exits immediately and no code below this point is executed.
When you're in a request trigger and the 2nd argument to the callback looks like a request (not a response) then CloudFront continues processing and assumes you did not want to generate a response. The request will be sent to the origin.
If you modify the request object in an origin request trigger, and then return it as shown above, this modifies what CloudFront sends to the origin, or in certain cases can even change which origin the request will be sent to, if your distribution has multiple origins.