Do I have to use S3 and EC2 as Virtual Server to host my files and
change hosting provider in order to use Cloudfront?
No you don't have to use S3 and/or EC2.
CloudFront does require an ORIGIN. This may be an EC2, an S3 Bucket, or another server that has nothing to do with AWS.
I understand EC2 is a hosting solution but what exactly is S3 then?
EC2 gives you access to compute capacity. It's a Virtual Server.
You can think of S3 as an FTP service. S3 allows you to store files, and retrieve files easily, and without the need for a server.
It can be cheaper then running a virtual Server just to serve files, it's scalable (with no configuration needed). It's also reliable as your files are stored in multiple locations for you.
In addition to being able to store and retrive files, Amazon does let you host static files over HTTP. For example: If you had a simple HTML site with some JS/CSS and images...you could upload all of them to S3 and ask Amazon to host those files for you (no web server required!).
You pay for storage of files, and for bandwidth ... but the price is often much cheaper then setting up a web server to do the same job.
Also is there any complexities involved in integrating Cloudfront and
S3 and potentially EC3?
There are a couple of gotcha's with CloudFront but it's not too difficult to setup.
When you setup a new CloudFront distribution you will be asked for an origin. You can either choose an S3 Bucket or a server location (e.g www.domain.com where you files are hosted, maybe this is powered by some EC2s, maybe it's shared hosting at GoDaddy, it doesn't matter!).
Some things to be careful of:
- You will need to get permissions right, particularly on the S3 bucket. CloudFront needs to be able to access the files.
- CloudFront is a CDN so it will cache files. If you change a file, CloudFront may not immediately know to update it for you. You may need to manually purge the file in question, or you may need to enable the use of cache busting through paramaters in your URL so that "file.css?v=1" is different from "file.css?v=2".