For stripping /api/ from the path, I don't know what would be the benefit of doing it at the origin request, rather than at the viewer request?
Cloudfront functions are pretty new, so some older docs might still reference lamdba@edge only.
Therefore stripping must be performed on the origin request, which is not supported by CloudFront Functions.
See https://docs.aws.amazon.com/AmazonCloudFront/latest/Develope...
I have used lamdba@edge and our primary use case was to rewrite url (to add languages information for example) so I'm sure it works in viewer request events.
I could be wrong as I did this lambda@edge a while ago, but the main difference between the two request event is that viewer request is done in all cases, while origin request is done only in case of cache miss.
[EDIT] you are right, updating the origin is indeed something that cannot be done on the viewer side. My bad, I should have checked earlier.
Only Lambda@Edge can help the scenario which I provided, which is also AWS's recommended solution. [1]
[0] https://docs.aws.amazon.com/AmazonCloudFront/latest/Develope...
[1] https://aws.amazon.com/blogs/architecture/serving-content-us...