Saturday, February 14, 2015

AWS Spot EC2 Instances for Elastic Beanstalk saves around 70-90% of instance costs over reserved or on-demand

    Amazon AWS is an excellent service - that Amazon runs very well.  There are opportunities to save between 25 and 60% - but there is and even better way to reduce costs for non-production development servers.
    On-demand instance cost for AWS resources can be reduced by 25% using no-upfront reservations or by 56% by purchasing the instance for 3 years.  However the use of the spot instance market allows a reduction from 80 to 90% - but not in beanstalk.
    There is however a way to reserve spot instances for elastic beanstalk through the .ebextension mechanism like we do for other types of EC2 instance customization.  There are the usual problems of not being compatible with auto-scaling but this price reduction is excellent for development instances.
    Enter the following .config with a spot price that is just above the lowest price across all regions for the past 3 months - so you run the lowest risk of loosing the instance.  For example I reserved the new C4.Large at 0.018 which is above the normal spot of 0.0161 - however this is a lot better than the on-demand price of 0.160 - or 10% of the normal price.
Note the spot price which is a reduction of 90% on the AWS EC2 on-demand price.  We will put this into the .ebextension directory in a config file

Add the following to your pom.xml if you are using "ebextensions" instead of the target ".ebextensions"



After you build your WAR and deploy it, you will initially see some scaling errors until the spot request is fulfilled.

As soon as your instance is up and the war completes deployment - the healthcheck will report a good instance.

    If you are running a set of development servers like 10 M3.xlarge instances at a on-demand price of $0.28/hour - this comes out to $67/day or $25,000/year.  Switching to using spot instances at the current stable price in us-east-1b of $0.0321 - but lets use $0.034 - would come out to $8/day or $3000/year - a cost savings of $22,000 at 88% off.  Actual savings would be more in line with $8,000 or 72% if you normally use 3yr reserved instances.

    Note that you can loose your instance at any time if the lowest spot price jumps.
    There are ways to get environment variables into the config files without resorting to commands or sh scripts - so we can change the spot price when we want to up the instance to a C4.8xlarge for example.


Total Pageviews