87700

Dynamically choose an S3 object to be served by CloudFront

Question:

Is it possible to have a custom origin server tell CloudFront to directly serve a file from an S3 bucket, similar to the way X-Sendfile works in Nginx? I'd like to avoid having to read the file from S3 and pipe it to CloudFront.

Answer1:

No, this isn't possible.

Once the request is sent from CloudFront to the origin server, the <em>only</em> thing CloudFront will do (unless an error occurs, of course) is return the origin server's response to the requester.

The only way that comes to mind in which this could really be possible would be if CloudFront followed HTTP redirects, which <a href="http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#ResponseCustomRedirects" rel="nofollow">it does not do</a>.

If you want to return content from elsewhere once the request has arrived at the origin, you'll have to fetch it and stream it back... which will probably perform better than you expect, if the bucket is in the same region as the origin server and your code is tight. The latency to S3 within a region is very low and the available bandwidth is high. I have an application that does exactly this, many thousands of times each day on a little t2 instance, so it's certainly viable.

Of course, with a single CloudFront distrubution, you can have multiple origins -- such as your server and S3. CloudFront can choose which origin will handle each request based on path pattern matching... but that's a static mapping, so I don't know whether it applies to what you're trying to do.

Recommend

  • Class 'HttpResponse' not found
  • has_many :through rails
  • Laravel - Accessing model value inside Query Builder
  • PHP multiple OR in if condition
  • Cassandra CQL paging for Composite key
  • Override a private method in the lib folder of a gem
  • WPF - MVVM Screen Management
  • Can i detect if a user canceled navigation from Google Maps App
  • Git cherry-Pick a batch of commits from a file
  • console.log printing statements in the wrong order for learnyounode node.js tutorial
  • Determining the length of a read stream in node js
  • Unzip archive in .Net CORE 1.0
  • Streaming screenshots over WebRTC as a video stream from iOS
  • Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no
  • Julia: How to give multiple workers access to functions that are 'include(…)' into a modul
  • How to read piped content in C?
  • JPA flush vs commit
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • MongoDb aggregation
  • Is there a way to do normal logging with EureakLog?
  • Play WS (2.2.1): post/put large request
  • Bad request using file_get_contents for PUT request in PHP
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • htaccess rewriting URLs with multiple forward slashes
  • Symfony2: How to get request parameter
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Is there a mandatory requirement to switch app.yaml?
  • File upload with ng-file-upload throwing error
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#
  • AngularJs get employee from factory
  • log4net write single file for each call to log.info
  • Getting error when using KSoap library to consume .NET web services
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?