Search code examples
amazon-web-servicesamazon-ec2amazon-cloudfront

Amazon EC2: load balancing / way to sync files / EC2 + CF


As I understand I can use EC2 as web server for my application. But how load balancer is working?

  1. For example I have one EC2 instance. In this way load balancer will not work. Am I right?

  2. For example I have few EC2 instances. In this way I can configure load balancer to balance between all my EC2 servers. Am I right?

  3. Application files at all instances should be synced? Is there is any Amazon tool to sync? Or I should use something like rsync or post commit hooks to sync files between EC2 instances?

  4. Is it possible to use one EC2 instance for web application (php + nginx) and for CDN (Cloud Front)? Or what is the better way to reach this: I need to store static files but I should access them from web application (php scripts) through file system. So I am going to use EC2 and Clod Front. But how can I get access?

Thanks for your time.


Solution

    1. Technically, the load belancer will work, it's just that it'll only balance the traffic to one instance.
    2. Correct. You register the instances with the elastic load balancer, and whilst those instances are healthy - it will respond to them.
    3. There's many different ways to sync files - it all depends on what you want to sync. Cloud Architecture is a little different to traditional architecture. For example, rather than loading the images onto the EBS volume, you'd try and offload them (and serve them) from S3. Therefore the only things you'd need to "sync" would be the webserver files themselves. You could use CloudFormation to roll out updates, post commit hooks and rsync are also good options. The challenge is to remember that it can scale / fail almost at will - so you need to ensure that each instance knows how to get the information and keep itself updated in isolation.
    4. Yes. It's called a custom origin. What you want to do though is put a url rewrite on the outbound server that rewrites the local urls to cloudfront domains.

    Hope that helps