# Aws spot instance

**URL:** <https://forums.suse.com/t/aws-spot-instance/10539>\
**Category:** Rancher 1.x\
**Created:** [May 23, 2018, 12:38pm UTC](https://forums.suse.com/t/aws-spot-instance/10539 "2018-05-23T12:38:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ernest\_Chen](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ernest\_Chen](https://forums.suse.com/u/Ernest_Chen)\
**Post date:** [May 23, 2018, 12:38pm UTC](https://forums.suse.com/t/aws-spot-instance/10539/1 "2018-05-23T12:38:15Z")

</div>

I would like to leverage aws spot instance to automatically create instances. I specified user data when creating the spot fleet with the following script:

sudo docker run -e CATTLE\_HOST\_LABELS=‘prod=true&worker1=true&worker2=true&worker4=true&worker5=true&web=true&worker7=true&worker6=true’ --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.10 [http://rancher.xxxxx.xxx:8080/v1/scripts/D6D5876284500A53F892:1514678400000:dt9LCdNL8LCCWm3XkyrulTBEI](http://rancher.xxxxx.xxx:8080/v1/scripts/D6D5876284500A53F892:1514678400000:dt9LCdNL8LCCWm3XkyrulTBEI)

So far it works as expected and whenever the spot instance got killed, it will re-create another instance and rancher will automatically launch the container required (the stacks are already defined earlier). The problem is that it takes up to 5 minutes to download the stack, extract and start. During that time, the rancher load balancer running on a separate on-demaind instance will try to re-direct traffic to the new host before the stacks are up and running and I will get bad gateway error.

How do I prevent traffic redirection before the stacks are fully ready?

---

<div class="post-metadata">

**Author:** ![jbacic](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/jbacic/32/3091_2.png) [@jbacic](https://forums.suse.com/u/jbacic)\
**Post date:** [May 23, 2018, 1:09pm UTC](https://forums.suse.com/t/aws-spot-instance/10539/2 "2018-05-23T13:09:31Z")

</div>

Did you set proper heatlchecks on the services? Rancher LB shouldn’t redirect traffic to non-healthy containers.

---

<div class="post-metadata">

**Author:** ![Ernest\_Chen](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ernest\_Chen](https://forums.suse.com/u/Ernest_Chen)\
**Post date:** [May 23, 2018, 1:46pm UTC](https://forums.suse.com/t/aws-spot-instance/10539/3 "2018-05-23T13:46:20Z")

</div>

Thanks for the pointer, I noticed that the healthcheck container on the spot instance turned green, but my other stacks are still downloading. Because I have one on-demand instance which is always running and trying to start the spot instance later, both running the same stacks. As a result, I get error every other request I made to the load balancer before the spot instance is fully ready.
