Toggle Elastic Beanstalk load balancer off/on with Terraform?

落爺英雄遲暮 提交于 2021-01-29 18:41:47

问题


  • Load balancers cost an hourly rate
  • (Re)creating EB costs uploads to S3 and takes a long time

So for EB that is sitting idle (used only during development), just as EC2 can be scaled down to 0 instances, how can the load balancer be toggled off (and later toggled back on)? Could Terraform be employed, such that the absence of the ALB is detected and gets recreated with an apply?

I already terminate EC2 instances under EB when idle, but all the while my unused load balancer is charging me! Ideally I'd have a zero cost during idle time, by also deleting the load balancer. But when I go to recreate the ALB when needed, Terraform state isn't explicitly tracking the ALB (it's managed by EB environment), so it doesn't get recreated.

I know Elastic Beanstalk environments can be created without load balancers. I'm hoping the "scalability" of AWS provides a cleaner and faster approach to just toggling the existence of the load balancer besides recreating the whole EB environment.


回答1:


You can temporarily disable all Elastic Beanstalk infrastructure that costs money, allowing you to suspend the application for free until you're ready to turn it back on, without the expense of destroying and recreating it from scratch.

Via the EB Environment Configuration:

  1. (temporarily) demote Capacity
    • from: Environment type: load balancing, auto scaling
    • to: Single-Instance Environment
  2. Delete the single instance and static ip it generates
  3. Just to be safe, ensure your autoscaling group config allows a maximum of 0 instances

Leave running for months this way, without paying a dime...

Then, You can turn everything back on the way it was quickly:

  1. Switch Load balancing back on and ensure autoscaling group has non-zero instance count.
  2. terraform refresh to import the new instance ids of your autoscaling targets
  3. resume using terraform as usual (e.g. plan, apply)


来源:https://stackoverflow.com/questions/56530721/toggle-elastic-beanstalk-load-balancer-off-on-with-terraform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!