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

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.

Related

How to load part of section directly from Akamai to AWS S3 without requesting the origin server?

I have one website, which is deployed on AWS instance and we have Akamai CDN. We are storing data in S3. We have few modules which do not require any processing from the web server and that can be directly served because those are pure static files say (RSS). Is there any way to load some links directly from Akamai to S3 without requesting the origin server?
For example, http://www.example.com/rss/1000.rss, can this /rss/* directly be configured in Akamai luna to load it from relevant S3 URL?
We tried sitefailover but it does not support the non property URLs Host names.
Create a new rule in Property Manager.
Add a match criteria, for /rss/*.
Add an Origin Server behavior.
Notes:
Set the Forward Host Header to Origin Hostname.
Set the Origin Server Hostname to a hostname that maps to your S3 bucket (replace yourbucket).
Make sure the files in the S3 bucket are publicly readable (public-read ACL).

Using mod_pagespeed with Cloudfront and 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.

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

Accessing files from S3 (mounted to EC2) using apache

I am observing that accessing files which is present on s3 mounted to ubuntu EC2 is little slow, when compared to accessing files from ubuntu EC2 itself - through apache.
My configuration is ,
S3 bucket -> Ubuntu EC2 (s3 mounted through s3fs on this machine) . Apache is running on EC2 , and files are accessed using Apache.
What i have observed is, if the request to server is valid ( i.e proper file request) - server takes time to reply, where is some error requests such as file not found or access denied requests are honored immediately.
My question is, has anybody had problems while accessing files sitting S3 buckets when they are mounted to EC2 through apache ( i know i could do cloudfront, but that doesn't serve my purpose as i need to protect files from unwanted access - that's why i have apache rules in place).
Any pointers are greatly helpful.
Thanks.
Don't use S3 for that. Use NAS!

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/