Search code examples
cachingamazon-web-servicesamazon-elastic-beanstalkamazon-cloudfront

Can I/Should I add Cloudfront to my webservice running on elastic beanstalk


Current situation

I have a Java Tomcat application running on ElasticBeanstalk. The application is a webservice that receives search queries and returns the results in Xml format. The webservice is only updated with new data once a month so any query sent at the end of the month will return identical results to one returned at the start of the month.

We take advantage of EB's load balancing so that usually just one EC2 instance is running but at time of peaks usage and another EC2 instance may get started.

To allow deployment of new versions Elastic Beanstalk we have a domain name on Route53, and a subdomain mapped to the the EB Application, customers use this subdomain in order to use the webservice.

This is working reasonably well, except peak usage can be somewhat higher than normal usage resulting in need more instances to be started increasing cost but also a slower response rate even with the extra machine.

Should I use CloudFront

I was wondering if I could use CloudFront to cache these responses, Im making these assumption

  1. There would be less peaks and troughs on EB
  2. I would save me money assuming cloudfront requests cheaper then extra load on EB
  3. It would improve response rate for customers not near my EB server, i.e EB server is based in EU but I have many US customers.

If so how do I do it

I went to try and create a Cloudfront Distribution but in the Original Domain Name field it only listed my s3 buckets not my S3 domain so havent gone any further.


Solution

  • I always put cloudfront in front of any solutions I deliver on AWS. In response to your specific questions:

    1. Most likely yes, it would off load some of the work that may go to an EC2 instance so it might prevent an extra instance from spinning up sometimes.
    2. Maybe, maybe not. It might save you money, but its also possible that it could end up costing you a fortune. Cloudfront can be abused by a hacker, if for no other reason than to give you a huge bill, so you may want to add a billing alert so you are not suprised by this.
    3. Yes, it all likelihood it will improve the responsiveness of you websites. Thats the prime reason I always use it.