0

I'm looking for a service that allows me to proxy/modify incoming requests inside AWS.

Currently I am using cloudfront, but that has limited functions.

I need to be able to see user agent strings and make proxy decisions based on that - like reverse proxying to another domain, or routing all requests to /index.html.

Anyone know of a service that within AWS - or outside of AWS.

1

1 Answer 1

1

It sounds like you are describing Lambda@Edge, which is a CloudFront enhancement that allows you to define Lambda functions that will fire at any of 4 hook points in the CloudFront signal flow, and modify the request or generate a dynamic response.

Viewer Request triggers allow inspection/modification of requests and dynamic generation of small responses before the cache lookup.

Origin Request triggers are similar, but fire after the cache is checked. They allow you to inspect and modify the request, including changing the origin server, path, and/or query string, or to generate a response instead of allowing CloudFront to proceed with the connection to the origin.

If the request goes to the origin, then once it returns, an Origin Response trigger can fire to modify the response headers or replace the response body with a different body you generate. The response after this trigger is finished with it is what gets stored in the cache, if cacheable.

Once a reaponse is cached, further firing of the Origin Request and Origin Response triggers doesn't occur for subsequent requests that can be served from the cache.

Finally, when the response is ready, whether it came from the cache or the origin, a Viewer Response trigger can modify it further, if desired.

Response triggers can also inspect many of the headers from the original request.

Lambda@Edge functions are written in Node.js, and are presented with the request or responses as simple structured objects that you inspect and/or modify.

Sign up to request clarification or add additional context in comments.

2 Comments

Seems like this is a great option. Is it possible to use one lambda@edge function for multiple cloudfront distributions?
Yes. You can associate a single function with multiple distributions. If you write it correctly, you can also use the same function for multiple triggers (e.g. Viewer Request and Viewer Response). If !(event.Records[0].cf.response), then the function is handling a request, otherwise it's handling a reaponse, but note that this is something you'd do only for administrative tidiness (one function instead of two), it doesn't have a performance impact.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.