Defining AutoScaling for Aurora DB Cluster in CloudFormation template

Viewed 2325

I need to add AutoScaling for my AWS Aurora DB Cluster, and I found this nice article about how to do it with the web console. But I couldn't find how to define it using CloudFormation template of the AWS::RDS::DBCluster resource.

Can someone direct me on how to define Auto Scaling Policies to my DB cluster using CloudFormation?

1 Answers

You'll need to use the Application Autoscaling service. Below is an example CFN script but note that I haven't created any instances - only the cluster and the scaling policy.

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

Also, take a look at aurora serverless.

Related