开发者

Possible to get image from Amazon S3 but create it if it doesn't exist

开发者 https://www.devze.com 2023-01-29 02:04 出处:网络
I\'m not sure how to word the question but here is what I am looking to do. I have a site that uses custom map tile overlays on a google map.

I'm not sure how to word the question but here is what I am looking to do.

I have a site that uses custom map tile overlays on a google map.

The javascript calls a php file on my server that checks to see if an existing map tile exists for the given x, y, and zoom level.

If if exists, it displays that image using file_get_contents.

If it doesn't exist, it creates the new tile then displays it.

I would like to utilize Amazon S3 store and serve the images since there could end being a lot of them and my server is slow. If I have my script c开发者_如何学Goheck to see if the image exists on amazon and then display it, I am guessing I am not getting the benefits of the speed and Amazons CDN. Is there a way to do this?

Or is there a way to try and pull the file from Amazon first then set up something on Amazon to redirect to my script if the files no there?

Maybe host the script on another of Amazons services? The tile generation is quite slow also in some cases.

Thanks


Ideas:

1 - Use CloudFront, but point it to a cluster of tile generation machines. This way, you can generate the tiles on demand, and any future requests are served right from Cloudfront.

2 - Use CloudFront, but back with with an S3 store of generated tiles. Turn on logging for the S3 bucket, so you can detect failed requests. Consume those logs on a schedule, and generate the missing tiles. This results in a cheaper way of generating tiles, but means that when a tile fails the user get's nothing.

3 - Just pre-generate all the tiles. Throw tasks in an SQS queue, then spin up a collection of EC2 instances to generate the tiles. This will cost the most up front, but all users get a fast experience.


I've written a blog post with a strategy for dealing with this. It's designed to make intelligent and thrifty use of CloudFront, maximize caching and deal with new versions of existing images. You may find the technique described there helpful. The example code shows how to handle different dimensions (i.e. thumbnails) of images. You could modify it to handle different zoom levels.

I need to update that post to support CloudFront custom origins, and I think that for your application you might be better off skipping S3 and using a custom origin. The advantage of a custom origin is simply that it's probably going to be easier to manage all of your images on your local filesystem compared to managing them on S3.

0

精彩评论

暂无评论...
验证码 换一张
取 消