【发布时间】:2017-10-29 20:20:41
【问题描述】:
我想创建一个Opsworks stack,带有一个Autoscaling Group,以便可以根据费用动态添加实例。
现在,对于我的环境,00h、6h、12h 和 18h 总是有很高的利用率。
我正在寻找一种在这些时间配置自动缩放的方法:在之前的每个小时,通过 Autoscaling Group 添加 4 个实例,其余时间只有一个实例在线。
我也在关注这个Document,以便实例通过Lambda Function 从层中注销。
这里是sn-p:
"InstanceRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"opsworks:AssignInstance",
"opsworks:DescribeInstances"
],
"Resource": [ "*" ]
}
]}
}
},
"InstanceProfile": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Path": "/",
"Roles": [{ "Ref": "InstanceRole" }]
}
},
"LaunchConfig": {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Properties" : {
"AssociatePublicIpAddress" : true,
"ImageId" : { "Fn::FindInMap": ["AWSRegionToAMI", { "Ref": "AWS::Region" }, "AMIID"] },
"InstanceType" : {"Ref" : "InstanceType"},
"IamInstanceProfile": {"Ref": "InstanceProfile"},
"EbsOptimized" : true,
"SecurityGroups" : [{ "Ref" : "SG" }],
"UserData" : {
"Fn::Base64": {
"Fn::Join" : ["",
["#!/bin/bash",
"sed -i'' -e 's/.*requiretty.*//' /etc/sudoers",
"pip install --upgrade awscli",
"INSTANCE_ID=$(/usr/bin/aws opsworks register --use-instance-profile --infrastructure-class ec2 --region us-east-1 --stack-id ",
{ "Ref": "StackID"}," --override-hostname $(tr -cd 'a-z' < /dev/urandom |head -c8) --local 2>&1 |grep -o 'Instance ID: .*' |cut -d' ' -f3) /usr/bin/aws opsworks wait instance-registered --region us-east-1 --instance-id $INSTANCE_ID
/usr/bin/aws opsworks assign-instance --region us-east-1 --instance-id $INSTANCE_ID --layer-ids ",{ "Ref": "myLayer" }
]]
}
}
}
},
"AutoScalingGroup": {
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"VPCZoneIdentifier": { "Ref": "subnetIds" },
"LaunchConfigurationName" : { "Ref" : "LaunchConfig"},
"LoadBalancerNames" : [{"Ref" : "ELB"}],
"MaxSize": { "Ref": "MaxSize" },
"MinSize": 1,
"Tags":
[{
"Key": "Name",
"Value": "opsworks_stack_id",
"PropagateAtLaunch": true
}],
}
},
如何配置这种类型的自动缩放?我应该使用Time-based 吗?
任何建议都非常感谢。
【问题讨论】:
-
您是否考虑过将自动缩放与 opsworks 一起使用? docs.aws.amazon.com/opsworks/latest/userguide/…docs.aws.amazon.com/opsworks/latest/userguide/…
-
可以,但还不够。我想我会同时使用两者;传统的自动缩放和基于时间的实例
标签: json amazon-web-services amazon-cloudformation autoscaling aws-opsworks