Using mod_pagespeed with Cloudfront and S3 - amazon-s3

We have a bunch of images that are loaded on Amazon S3. Right now we directly call these images with the S3 URL. I would like to install Cloudfront CDN and mod_pagespeed to resize these images and optimize them. The web server itself isn't hosted on Amazon at all.
How can I get Cloudfront to cache the mod_pagespeed's resized images? My idea was to spin up an EC2 instance and use it as a reverse proxy to S3. This EC2 instance would have mod_pagespeed installed. So it would go Cloudfront -> EC2 proxy -> S3. So far I haven't been able to get this to resize the images. It all works, just not the mod_pagespeed part.
We're not wanting the images to pulled to the web server out of Amazon as they would waste a lot of bandwidth. I want the images from S3 to be resized either on the new EC2 instance or some other way inside of Amazon.
Anyone have any recommendations?

Take a look at AWS Lambda - there are a number of examples of doing exactly what you're trying to do with it.

Related

AWS Next.js on EC2 caching

I'm planning to use Next.js SSR/SSG/ISR on Amazon's EC2 and store images on S3 Bucket. Also to add CloudFront CDN on top of it.
The question is:
Should I cache images from S3 in Next.js (which is in EC2) thus "doubling" images (origin in S3, optimised instances in EC2 Next.js cache), or it makes no sense, since everything is located within one cloud (AWS) and covered with CDN layer (CloudFront)?
Or there is a way to move next.js caching to CloudFront?
I do understand that next/image is providing image optimisation (different sizes and quality), but I'm bothered by "doubling" the images, thus paying more for storage.
P.S. I've seen this question, I'm just not experienced with lambda, so currently looking for something I understand already.
Cloudfront gives you the option to have different origin for different behaviours and you can also apply different cache policy per behaviour. What you can do is have a behaviour for /images which will go to S3 and Default behaviour will point to Ec2 origin.

How can I host my website on an EC2 Server using Apache but host my images on S3 under the same sub domain?

So I have my website hosted on an EC2 server running apache. All works fine and well.
The issue I'm having is that I want my images hosted on S3 (and possibly cached on CloudFront), not on my EC2 server, but want both accessible under the same domain/subdomain.
For example say my website is www.helloworld.com. I want my images to be accessible at www.helloworld.com/images/foobar.png. I want foobar.png to be hosted on S3 and not each one of my EC2 servers though. How can I go about doing this?
Is there and configuration I can do in the AWS console or are there any rewrite rules I can use in Apache? I know I could always just set up a controller that will download the images from S3 and forward them to the user, but this seems wrong to me.
For that you need to put a load-balancer/proxy in front to intercept all requests and dispatch accordingly. That may not be a bad idea anyway (for availability reasons), but a separate host name for images should not be a problem, either (it's not like users will have to see or type those URL).
Using CloudFront, you can have CloudFront receive the initial requests, then based on the path, forward the request to either your EC2 instance or to your S3 bucket.
For example, you could setup the following:
A CloudFront behaviour that upon a path under /images/ would use an S3 origin, and
A default (for everything else) would go to your EC2 instance origin.

AWS s3 configuration to avoid waiting time for multiple request

I have static content uploaded on S3 bucket.
When I hit URL for the First time, the contents take while to load. It has a single html page with multiple CSS and JS.
So is there any kind on configuration needed at S3 level to optimize.
I am trying to figure out settings such as number of connections like we have in Apache.
There are no configurations available for Amazon S3. It just works!
Some ideas for speeding your download:
Create a bucket that is located closer to you/your users (less latency)
Zip your files before uploading to Amazon S3 (faster download)
Check the Network console in your web browser to determine where the time is being taken

Hosting dynamic website in Amazon server

I am working on a project where we are hosting our files(only uploaded by the user) in S3 Amazon server. Now the problem is the contents hosted with amazon is loading fastly. But the JS, CSS and CSS images(Very small images) which hosted in our server is taking too much time to load. Is there anyway to host our entire dynamic website to Amazon S3 and is it possible to configure the DNS to amazon?
Host your static files to S3 as well.
Create a bucket named static.yourcompany.com
CName the bucket URL as static.yourcomapany.com
In your webpages, use absolute path for CSS, JS, images with base URL as http://static.yourcompany.com
You may want to leverage tools like JetS3t for syncing the files with the latest changes.
Refer:
How to alias your subdomain with S3
JetS3t Docs
Virtual Hosting of Buckets
Host Your Static Website on S3
You can also read this blog, the author has described the process in a very detailed manner
http://geekospace.com/hosting-static-web-sites-in-aws-simple-storage-service/
For the dynamic part of your website look into http://aws.amazon.com/elasticbeanstalk/ but route 53 is essentially a way to configure DNS to amazon. http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html

Using amazon s3, upload files using their servers but URL should appear to be from mine

Is it possible to upload files to amazon S3, using their servers (i.e. my server shouldn't be used in the upload process)?
I also want the URL to appear to be uploading to my server, is this possible?
Look here for instructions on how to setup your CNAME record so that one of your subdomains can be an alias for an Amazon S3 bucket.
Depending on your needs, you might not want "s3.amazonaws.com" to appear on your web site or service. For example, if you host your web site's images on Amazon S3, you might prefer http://images.johnsmith.net/ to http://johnsmith-images.s3.amazonaws.com/