官术网_书友最值得收藏!

Auto scaling

If you've applied the patterns and followed the practices enumerated here, you are on the road to success. Unfortunately, success often comes more swiftly than you expect. A mention on Hacker News, Reddit, or Twitter can send waves of traffic your way. Let's take a look at how Amazon's auto scaling feature can help us to meet the demand in a cost effective way. First, we will define a launch configuration for our product—this should go into the instanceAZ1c.tf file:

resource "aws_launch_configuration" "asg_conf" {
name = "book-asg-config"
image_id = "ami-001e1c1159ccfe992"
instance_type = "t2.micro"
}

Then, add an autoscaling group to the same file, which encompasses all AZs, so that the workload gets distributed evenly:

resource "aws_autoscaling_group" "book_group" {
availability_zones = ["us-east-1a","us-east-1b","us-east-1c"]
name = "book-group-asg"
max_size = 5
min_size = 2
health_check_grace_period = 300
health_check_type = "ELB"
force_delete = true
launch_configuration = "${aws_launch_configuration.asg_conf.name}"
}

And add a policy that defines the configuration for capacity, causes, adjustment, and cool down, which in this case puts the policy to sleep for an arbitrary five minutes:

resource "aws_autoscaling_policy" "bat" {
name = "book-policy-ASG"
scaling_adjustment = 4
adjustment_type = "ChangeInCapacity"
cooldown = 300
autoscaling_group_name = "${aws_autoscaling_group.book_group.name}"
}
主站蜘蛛池模板: 随州市| 高青县| 廉江市| 潮州市| 琼结县| 台东市| 靖江市| 腾冲县| 吴桥县| 博爱县| 尤溪县| 新建县| 广灵县| 景东| 蒙城县| 土默特右旗| 和林格尔县| 夏津县| 凭祥市| 长岭县| 从化市| 广南县| 临高县| 万盛区| 凌海市| 三河市| 怀来县| 土默特右旗| 乌兰浩特市| 方城县| 隆化县| 武清区| 新建县| 曲松县| 西平县| 大理市| 梁河县| 商河县| 乐安县| 三明市| 呼和浩特市|