在CloudFormation模板中定义Aurora数据库集群的AutoScaling

时间:2018-11-15 16:07:33

标签: amazon-web-services amazon-cloudformation autoscaling amazon-rds-aurora

我需要为我的AWS Aurora数据库集群添加AutoScaling,并且发现了nice article这是有关如何使用Web控制台执行此操作的信息。但是我找不到如何使用AWS::RDS::DBCluster资源的CloudFormation模板来定义它。

有人可以指导我如何使用CloudFormation为我的数据库集群定义Auto Scaling策略吗?

1 个答案:

答案 0 :(得分:4)

您需要使用Application Autoscaling服务。以下是一个示例CFN脚本,但请注意,我还没有创建任何实例-仅创建了集群和扩展策略。

AWSTemplateFormatVersion: 2010-09-09
Resources:
  MyDatabase:
    Type: AWS::RDS::DBCluster
    Properties:
      Engine: aurora
      EngineVersion: 5.6.10a
      MasterUsername: example
      MasterUserPassword: examplepassword

  AutoScalerTarget:
    Type: AWS::ApplicationAutoScaling::ScalableTarget
    Properties:
      MinCapacity: 1
      MaxCapacity: 8
      ResourceId: !Sub "cluster:${MyDatabase}"
      ScalableDimension: rds:cluster:ReadReplicaCount
      ServiceNamespace: rds
      RoleARN: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/rds.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_RDSCluster"

  AutoScaler:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      ScalingTargetId: !Ref AutoScalerTarget
      ServiceNamespace: rds
      PolicyName: Example
      PolicyType: TargetTrackingScaling
      ScalableDimension: rds:cluster:ReadReplicaCount
      TargetTrackingScalingPolicyConfiguration:
        PredefinedMetricSpecification:
          PredefinedMetricType: RDSReaderAverageCPUUtilization
        TargetValue: 50.0
        ScaleOutCooldown: 300
        ScaleInCooldown: 300
        DisableScaleIn: False

还要看一下aurora serverless