通过 terraform 管理 Auto Scaling 组 [英] Managing Auto Scaling Group via terraform

查看:16
本文介绍了通过 terraform 管理 Auto Scaling 组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个通过 terraform 管理的自动缩放组.我希望该 Auto Scaling 组能够根据我们的营业时间扩大和缩小规模.

Let say I have a auto-scaling group which I manage via terraform. And i want that auto scaling group to scale up and scale down based on our business hours .

用于管理 ASG 的 TF 模板:

The TF template for managing ASG :

resource "aws_autoscaling_group" "foobar" {
  availability_zones        = ["us-west-2a"]
  name                      = "terraform-test-foobar5"
  max_size                  = 1
  min_size                  = 1
  health_check_grace_period = 300
  health_check_type         = "ELB"
  force_delete              = true
  termination_policies      = ["OldestInstance"]
}

resource "aws_autoscaling_schedule" "foobar" {
  scheduled_action_name  = "foobar"
  min_size               = 0
  max_size               = 1
  desired_capacity       = 0
  start_time             = "2016-12-11T18:00:00Z"
  end_time               = "2016-12-12T06:00:00Z"
  autoscaling_group_name = aws_autoscaling_group.foobar.name
}

正如我们在这里看到的,我必须为操作设置一个特定的日期和时间.

As we can see here i have to set a particular date and time for the action.

我想要的是:我想在周六晚上 9 点将当前容量缩小 10%,然后又想在周一早上 6 点扩大 10%.

what I want is : I want to scale down on saturday night 9 pm by 10% of my current capacity, and then again want to scale up by 10% on monday morning 6 am .

我怎样才能做到这一点.

How can I achieve this.

非常感谢任何帮助.请告诉我如何解决这个问题.

Any help is highly appreciated. Please let me know how to get through this.

推荐答案

解决方案并不简单,但可行.所需的步骤是:

The solution is not straightforward, but is doable. The required steps are:

  • 创建一个缩小 ASG 的 Lambda 函数(例如使用 Boto3 和 Python)
  • 分配具有正确权限的 IAM 角色
  • 为每个星期六晚上 9 点"创建一个 Cron 触发器;使用 aws_cloudwatch_event_rule
  • 使用之前创建的 Cron 触发器和 Lambda 函数创建一个 aws_cloudwatch_event_target
  • 重复放大

这个模块 可能会满足您的需求,您只需编写 Lambda 代码并使用该模块按计划触发它.

This module will probably fit your needs, you just have to code the Lambda and use the module to trigger it on a schedule.

这篇关于通过 terraform 管理 Auto Scaling 组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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