I'm having trouble making cloudfront work with multiple origins.
I have two origins:
ORIGIN 1
Path: Default (*)
Origin: Custom-example1.com/p
ORIGIN 2
Path: ns/
Origin: Custom-example2.com/Produtos
I can access the original and default origin, but not the second.
I have e.g an image from the second origin I want to access:
http://example2.com/Produtos/06/D12-1365-006/D12-1365-006_detalhe1.jpg
How do I access the image via the second origin?
My site is cdn.mysite.com.
CloudFront provides two mechanisms related to the url-path.
One is the cache behavior path pattern that defines which paths are routed to which origins.
The path pattern /foo/*
will send all requests matching /foo/*
to the specified origin, using the path in the original request, so GET /foo/bar
on the incoming request will be sent as-is, GET /foo/bar
on the outgoing request to the origin
...unless... the path is modified by the origin path, which adds a prefix to the beginning of every outgoing request to the origin.
If the origin, above, had an origin path of /baz
, then the outgoing request to the origin would be GET /baz/foo/bar
.
There is, then, no mechanism for removing path components -- only for adding them.
No configuration options can remove components of the path prior to forwarding the request to the origin. If GET /foo/bar
should be forwarded to the origin as GET /bar
... CloudFront does not currently have that capability.
CloudFront, by itself, does not have the ability to remove or otherwise rewrite the path that will be sent to the origin, but Lambda@Edge does. Lambda@Edge is a CloudFront feature that allows you to configure triggers that fire at 4 distinct points during request processing, and modify portions of the request (including the path and headers) or the response (headers), using code written in Node.js.
CloudFront creates a data structure representing the request attributes and invokes the Lambda function, passing the structure as the event
argument. The Lambda function's response modifies the CloudFront behavior accordingly.
There are 4 trigger points. You can use any combination of them on each Cache Behavior.
Cache-Control
headers that you want. Setting Cache-Control
headers, here, affects both CloudFront and browser cache behavior. This trigger does not fire on errors, only origin responses with HTTP status codes < 400.For the application discussed here, the solution requires a Lambda@Edge Origin Request trigger, to remove a known prefix from the request path after the cache is checked, but before the request is sent to the origin server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With