Search code examples
amazon-web-servicesamazon-cloudfront

Cloudfront Reverse Proxy 502 External API


I'm trying to create a reverse proxy using cloudfront that touches an external API. I'm trying to use this as an internal tool to track requests to this API and perform specific actions based on those requests.

I'm receiving a 502 from CloudFront. I have the origin set as the external API I want to forward my requests to and I'm using a custom cache policy that disables cache and forwards all headers/query/etc to the origin.

Is this possible with CloudFront or maybe I need to come up with a new solution?


Solution

  • CloudFront is a CDN service - think cached copies of static assets like JavaScript/CSS files, images, etc. It is not intended for use in this manner, and the fact you needed to effectively disable caching entirely is a clear indicator of that.

    What you're actually looking for is an API Management platform/product. In your case, since you're already on AWS, you'd probably use AWS API Gateway for this. You can configure the gateway to proxy requests to the target API (whether internal or external) and generate the necessary events/logs for you to act upon elsewhere in your processing.