使用Terraform开启/关闭Elastic Beanstalk负载平衡器? [英] Toggle Elastic Beanstalk load balancer off/on with Terraform?

查看:103
本文介绍了使用Terraform开启/关闭Elastic Beanstalk负载平衡器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 负载均衡器按小时收费
  • (重新)创建EB费用需要上载到S3,并且花费很长时间

因此,对于处于空闲状态的EB(仅在开发期间使用),就像EC2可以缩减为0个实例一样,如何关闭负载平衡器(然后又重新打开)?是否可以使用Terraform,以便检测到ALB的缺失并通过应用重新创建?

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?

我已经在空闲时终止了EB下的EC2实例,但是一直以来我未使用的负载均衡器正在向我收费!理想情况下,通过删除负载均衡器,我在空闲时间的成本为零.但是,当我在需要时重新创建ALB时,Terraform状态并未明确跟踪ALB(它是由EB环境管理的),因此不会重新创建它.

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.

我知道可以在没有负载平衡器的情况下创建Elastic Beanstalk环境.我希望AWS的可扩展性"提供一种更干净,更快速的方法来切换负载均衡器的存在除了重新创建整个EB环境之外.

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.

推荐答案

您可以临时禁用所有需要付费的Elastic Beanstalk基础架构,从而允许您免费暂停应用程序,直到准备将其重新打开为止,而无需从头开始销毁并重新创建它的费用.

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.

通过EB环境配置:

  1. (暂时)降级容量
    • 来自:环境类型:负载平衡,自动缩放
    • 到:单实例环境

以这种方式离开几个月,不用支付一毛钱...

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

然后,您可以快速恢复一切:

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

  1. 重新打开负载平衡,并确保自动伸缩组的实例计数为非零.
  2. terraform refresh 导入自动缩放目标的新实例ID
  3. 照常使用地形进行恢复(例如, plan apply )
  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)

这篇关于使用Terraform开启/关闭Elastic Beanstalk负载平衡器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆