【问题标题】:configure the autoscaling at specific hours在特定时间配置自动缩放
【发布时间】: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 吗? 任何建议都非常感谢。

【问题讨论】:

标签: json amazon-web-services amazon-cloudformation autoscaling aws-opsworks


【解决方案1】:

您可以使用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 * * *

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    • 2017-01-30
    • 1970-01-01
    • 2015-12-31
    • 2017-05-30
    • 1970-01-01
    • 2019-06-22
    相关资源
    最近更新 更多