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

查看:23
本文介绍了使用 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 环境配置:

Via the EB Environment Configuration:

  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. 照常使用 terraform(例如 planapply)
  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天全站免登陆