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

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}"
}
主站蜘蛛池模板: 抚远县| 宜州市| 安顺市| 衡山县| 赣州市| 望都县| 榕江县| 凌源市| 栖霞市| 昭通市| 武邑县| 钟祥市| 弥勒县| 伊金霍洛旗| 博客| 洪泽县| 泉州市| 永修县| 浏阳市| 揭东县| 双柏县| 奉节县| 云梦县| 延边| 清徐县| 东乡| 彩票| 梅州市| 尼勒克县| 朝阳市| 化州市| 六安市| 福建省| 河北区| 陕西省| 嘉禾县| 建阳市| 永靖县| 两当县| 禹城市| 东乌珠穆沁旗|