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

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}"
}
主站蜘蛛池模板: 桐梓县| 闽侯县| 永福县| 甘泉县| 西华县| 朝阳市| 宣汉县| 逊克县| 美姑县| 元氏县| 襄城县| 石嘴山市| 新昌县| 三亚市| 安阳县| 年辖:市辖区| 岱山县| 沂南县| 沅江市| 亚东县| 亚东县| 溆浦县| 沂源县| 新沂市| 舒兰市| 丹东市| 潮安县| 青冈县| 裕民县| 基隆市| 海口市| 巴彦淖尔市| 河津市| 格尔木市| 临桂县| 石林| 宜都市| 离岛区| 密山市| 自治县| 略阳县|