gpt4 book ai didi

json - 配置在特定时间自动缩放

转载 作者:行者123 更新时间:2023-12-03 07:45:56 25 4
gpt4 key购买 nike

我想创建一个Opsworks stack ,带有 Autoscaling Group以便可以根据费用动态添加实例。现在,对于我的环境来说,00h、6h、12h 和 18h 总是有很高的利用率。我正在寻找一种在这些时间配置自动缩放的方法:在之前的每个小时,按 Autoscaling Group 添加 4 个实例。 ,其余时间只有一个实例在线。

我也在关注这个Document ,以便实例通过 Lambda Function 从层取消注册.

这是片段:

  "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 ?非常感谢任何建议。

最佳答案

您可以使用AWS::AutoScaling::ScheduledAction在高利用率时段前一小时自动扩展您的 AutoScalingGroup 资源(并在高利用率时段后 30 分钟等情况下缩小规模):

ScaleUp: 
Type: AWS::AutoScaling::ScheduledAction
Properties:
AutoScalingGroupName: !Ref AutoScalingGroup
MinSize: 5
Recurrence: 0 23,5,11,17 * * *
ScaleDown:
Type: AWS::AutoScaling::ScheduledAction
Properties:
AutoScalingGroupName: !Ref AutoScalingGroup
MinSize: 1
Recurrence: 30 0,6,12,18 * * *

关于json - 配置在特定时间自动缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44243928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com