15

I have one infra that use amazon elastic beanstalk to deploy my application. I need to scale my app adding some spot instances that EB do not support.

So I create a second autoscaling from a launch configuration with spot instances. The autoscaling use the same load balancer created by beanstalk.

To up instances with the last version of my app, I copy the user data from the original launch configuration (created with beanstalk) to the launch configuration with spot instances (created by me).

This work fine, but:

  1. how to update spot instances that have come up from the second autoscaling when the beanstalk update instances managed by him with a new version of the app?

  2. is there another way so easy as, and elegant, to use spot instances and enjoy the benefits of beanstalk?

UPDATE

Elastic Beanstalk add support to spot instance since 2019... see: https://docs.aws.amazon.com/elasticbeanstalk/latest/relnotes/release-2019-11-25-spot.html

3
  • 1
    wondering if there is any changes to this now that AWS spot fleets are out ?
    – webofmars
    Sep 1, 2019 at 9:41
  • @webofmars.... elasticbeanstalk already supports spot instances Jul 21, 2020 at 21:54
  • 1
    yes only 2 months after my initial comment ;-)
    – webofmars
    Jul 22, 2020 at 10:27

4 Answers 4

15

I was asking this myself and found a builtin solution in elastic beanstalk. It was described here as follows:

  • 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.

I personally would just use the on-demand price for the given instance type given this price is the upper boundary of what you would be willing to pay. This reduces the likelihood of being out-priced and thus the termination of your instances.

This might be not the best approach for production systems as it is not possible to split between a number of on-demand instances and an additional number of spot instances and there might be a small chance that there are no spot instances available as someone else is buying the whole market with high bids.

For production use cases I would look into https://github.com/AutoSpotting/AutoSpotting, which actively manages all your auto-scaling groups and tries to meet the balance between the lowest prices and a configurable number or percentage of on-demand instances.

6
  • Thanks for your answer @jan-prieser. I already see the first solution, but, as you said, is not a good solution to production. About the "autospotting" mensioned, I don't see how the deploy works to new versions of application (e.g. with rolling updates). But I'll to study more about it. Jul 19, 2018 at 22:14
  • @GeanRibeiro the deployment and rolling updates are still handled by elastic-beanstalk when using auto-spotting. it would create new on-demand instances with the updated application and delete the old spot-instances from the targetgroups. autospotting will then find the new on-demand instances in the targetgroups and replaces them again with spot-instances running the new version. Aug 16, 2018 at 16:16
  • 3
    Autospotting is really nice. Easy to configure and can be tagged with any autoscaling groups. @GeanRibeiro You can keep the desired set of on demand instances to make sure that they are not getting replaced by the spots.
    – Babu
    Sep 3, 2018 at 15:33
  • 1
    The author of AutoSpotting here, @jan-prieser thanks for the recommendation to use it, I always love seeing such feedback from my users. Regarding the Beanstalk setup, it should work without significant changes to your stack, all you need is tagging the AutoScaling group. Please let me know if you ran into any issues with it. If you have any suggestions about documentation improvements regarding the Beanstalk setup, I would really appreciate a PR on Github. Oct 30, 2018 at 23:08
  • This solution unfortunately doesn't work with Windows Beanstalks, hopefully save someone else some time.
    – John C
    Jan 30, 2019 at 0:05
10

As of 25th November 2019, AWS natively supports using Spot Instances with Beanstalk.

Spot instances can be enabled in the console by going to the desired Elastic Beanstalk environment, then selecting Configuration > Capacity and changing the Fleet composition to "Spot instance enabled".

There you can also set options such as the On-Demand vs Spot percentage and the instance types to use.

More information can be found in the Beanstalk Auto Scaling Group support page

1
2

Here at Spotinst, we were dealing with exactly that dilemma for our customers.

As Elastic Beanstalk creates a whole stack of services (Load Balancers, ASG’s, Route 53 access point etc..) that are tied together, it isn’t a simple task to manage Spots within it.

After a lot of research, we figured that removing the ASG will always be prone to errors as keeping the configuration intact gets complex. Instead, we simply replicate the ASG and let our Elastigroup and the ASG live side by side with all the scaling policies only affecting the Elastigroup and the ASG configuration updates feeding there as well.

With the instances running inside Elastigroup, you achieve managed Spot instances with full SLA.

Some of the benefits of running your Spot instances in Elastigroup include:

1) Our algorithm makes live choices for the best Spot markets in terms of price and availability whenever new instances spin up.

2) When an interruption happens, we predict it about 15 minutes in advance and take all the necessary steps to ensure (and insure) the capacity of your group.

3) In the extreme case that none of the markets have Spot availability, we simply fall back to an on-demand instance.

0

Since AWS clearly states that Beanstalk does not support spot instances out-of-the-box you need to tinker a bit with the thing. My customer wanted mixed environment (on-demand + spot) and full spot. What I created for my customer was the following (I had access to GUI only):

  1. For the mixed env:

    • start the env with regular instance;
    • copy the respective launch configuration and chose spot instances during the process;
    • edit Auto Scaling Group and chose the lc you just edited + be sure to change Termination Policy to NewestInstance. Such setup will allow you to have basic on-demand fleet (not-terminable) + some extra spots if required, e.g., higher-than-usual traffic. Remember that if you terminate the environment and recreate it then all of your edits will be removed.
  2. For full spot env:

    • similar steps as before with one difference - terminate the running instance and wait for ASG to launch a new one. If you want it to do without downtime, just give an extra instance for the Desired number, wait for it to launch and then terminate on-demand one.
1
  • We've written a custom resource provider that automates this for us in a CFN template, bash mock here: github.com/ab77/…
    – ab77
    Nov 9, 2019 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.