I've followed this AWS image resizing blog post to resize images in my S3 bucket on the fly and return them when requested using the bucket’s static website hosting endpoint. It works fine for me when I type the URL into a web browser address bar.
I can see 2 redirects happening when I do this (if the resized image hasn't been generated yet): First, the S3 endpoint will 404 redirect to API gateway URL The lambda function is called to generate the resized image, and API gateway redirects the browser back to the endpoint URL again. Now that the resized image is there, it gets displayed.
What I'm aiming to do is display the dynamically resized images in web pages, so I've simply tried to place the endpoint URL for a resized image in img tags eg. <img src="http://YOUR_BUCKET_WEBSITE_HOSTNAME_HERE/300×300/blue_marble.jpg">
When I do this, nothing shows up in my web pages. In the browser console, I can see an error message - it's trying to GET the API gateway URL, and the error is ERR_TOO_MANY_REDIRECTS
Is there a way for me to display the resized images in web pages?
If not, what would I need to do to modify this approach to resize images to predefined sizes upon upload to S3 instead?
Thanks!