问题
- 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:
- (temporarily) demote
Capacity
- from:
Environment type: load balancing, auto scaling
- to:
Single-Instance Environment
- from:
- Delete the single instance and static ip it generates
- 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:
- Switch Load balancing back on and ensure autoscaling group has non-zero instance count.
terraform refresh
to import the new instance ids of your autoscaling targets- resume using terraform as usual (e.g.
plan
,apply
)
来源:https://stackoverflow.com/questions/56530721/toggle-elastic-beanstalk-load-balancer-off-on-with-terraform