27

We need to serve the same image in a number of possible sizes in our app. The library consists of 10's of thousands of images which will be stored on S3, so storing the same image in all it's possible sizes does not seem ideal. I have seen a few mentions on Google that EC2 could be used to resize S3 images on the fly, but I am struggling to find more information. Could anyone please point me in the direction of some more info or ideally, some code samples?

Tip

It was not obvious to us at first, but never serve images to an app or website directly from S3, it is highly recommended to use CloudFront. There are 3 reasons:

  1. Cost - CloudFront is cheaper
  2. Performance - CloudFront is faster
  3. Reliability - S3 will occasionally not serve a resource when queried frequently i.e. more than 10-20 times a second. This took us ages to debug as resources would randomly not be available.

The above are not necessarily failings of S3 as it's meant to be a storage and not a content delivery service.

RunLoop
  • 20,288
  • 21
  • 96
  • 151
  • may I ask you what final solution you implemented? – alapeno Oct 06 '15 at 18:03
  • 3
    @alapeno At the end of the day, we created the thumbnails on our server and then uploaded them to S3. It was just easier than setting up another EC2 instance. However, you may want to look into using something like Amazon Lambda which is less overhead than managing EC2 – RunLoop Oct 07 '15 at 10:42

2 Answers2

14

Why not store all image sizes, assuming you aren't talking about hundreds of different possible sizes? Storage cost is minimal. You would also then be able to serve your images up through Cloudfront (or directly from S3) such that you don't have to use your application server to resize images on the fly. If you serve a lot of these images, the amount of processing cost you save (i.e. CPU cycles, memory requirements, etc.) by not having to dynamically resize images and process image requests in your web server would likely easily offset the storage cost.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • @HermanJ.RadtkeIII Indeed the question was about "on demand" image resizing, but in looking at the use case mentioned here it did not seem like the best approach, so I offered an alternative, which apparently the OP thought was a good solution. – Mike Brant Feb 22 '16 at 15:47
6

What you need is an image server. Yes, it can be hosted on EC2. These links should help starting off: https://github.com/adamdbradley/foresight.js/wiki/Server-Resizing-Images http://en.wikipedia.org/wiki/Image_server

d33pika
  • 1,997
  • 14
  • 24
  • 1
    using EC2 will give me quicker access to the images stored in s3? because if I use a custom server i'll need to downdload the image then process it – Raphael Isidro Jul 17 '13 at 15:50
  • Your Image Server can run on EC2 – d33pika Jul 18 '13 at 03:45
  • 6
    an advantage to using EC2 for manipulation of the S3 images is that Amazon doesn't charge for data transfers between S3 and EC2-- depending on your volume this could save you some money. – user101289 Jan 31 '14 at 16:24