- Newest
- Most votes
- Most comments
Thanks for the detailed description. You are getting 403 Forbidden due to the origin request policy AllViewer being used. In this case, when you access the website via CloudFront URL, the Host header similar to d12345678.cloudfront.net will be forwarded to the Lambda which will not be recognized, resulting in 403.
The solution is to create your custom origin request policy and only forward the necessary values (but not the Host header.)
This has to be configured at both ends: in the lambda and in CloudFront.
Function URL configuration:
- Auth type: AWS_IAM
- CORS are irrelevant if no CORS protocol is involved, but you are likely to run into them even with localhost
CloudFront configuration:
- origin access with signed requests
- CachingDisabled policy
- OPTIONS caching setting is irrelevant since caching is disabled via CachingDisabled policy
- Managed-AllViewerExceptHostHeader request policy
- No response policy
This blog post has several detailed examples of different configurations that work: https://dev.to/rimutaka/aws-lambda-with-cloudfront-cors-authorization-and-caching-examples-1i9c
Please check out this blog if you haven't already - https://aws.amazon.com/blogs/networking-and-content-delivery/using-amazon-cloudfront-with-aws-lambda-as-origin-to-accelerate-your-web-applications/
Relevant content
- asked 2 years ago
- asked 3 years ago
- AWS OFFICIALUpdated 9 months ago

Thank you, it works so well, for my case, I also need to also forward
originanduser-agentbut it is because of my lambda function code.