Codementor Events

Spot Instances and Elastic Beanstalk

Published Nov 26, 2019

We’ve been using elastic beanstalk as our go to solution to deploy micro services, it is simple, intuitive and has an easy to manage dashboard.

As with all micro services platform, the cost of running all these services across 3 environments(dev, uat, prod) adds up pretty quickly. As a solution for the above we started exploring Spot Instances for our non production(we’ll explore this later) environments.

Following are the steps required to configure your elasticbeanstalk environment for spot instances.

  • Add a file under the .ebextensions folder, for our setup we’ve named the file as spot_instance.config (the .config extension is important), paste the content available below in the file
    https://gist.github.com/rahulmamgain/93f2ad23c9934a5da5bc878f49c91d64
  • The value for EC2_SPOT_PRICE, can be set through the elastic beanstalk environment configuration.
  • To disable the usage of spot instances, just delete the variable from the environment settings.
  • If the environment already exists and the above settings are updates, the older auto scaling group will be destroyed and a new one is created.
  • The environment then submits a request for spot instances which can be seen under Spot Instances tab on the EC2 dashboard.
  • Once the request is fulfilled the instance will be added to the new cluster and auto scaling group.
  • You can use Spot Advisor tool to ascertain the best price for the instances in use.
  • A price point of 30% of the original price seems like a decent level.

What To Look Out For

The reason we are not planning to use it in the production environment, because elastic beanstalk has no fallback method to use on demand or reserved instances in case the spot instance request can not be fulfilled.
Furthermore, if there are pending spot instance requests, for an elastic beanstalk environment, the environment termination might give issues.

Discover and read more posts from Rahul Mamgain
get started
post commentsBe the first to share your opinion
Show more replies