2
votes

I am trying to add auto-scaling to multiple Dynamodb tables, since all the tables would have the same pattern for the auto-scaling configuration.

I can of course create scalableTarget again and again but it’s repetitive.

I was wondering if it is possible to re-use the scalable targets

"DDBTable": {
   "Type": "AWS::DynamoDB::Table",
   "Properties": {
       "TableName": "Banner_v1", 
       ...
   }
},
 
 "WriteCapacityScalableTarget": {
        "Type": "AWS::ApplicationAutoScaling::ScalableTarget",
        "Properties": {
            "MaxCapacity": 15,
            "MinCapacity": 5,
            "ResourceId": {
                "Fn::Join": [
                    "/",
                    [
                        "table",
                        {
                            "Ref": "DDBTable"
                        }
                    ]
                ]
            },
            "RoleARN": {
              "Fn::ImportValue" : "ScalingRoleArn"
            },
            "ScalableDimension": "dynamodb:table:WriteCapacityUnits",
            "ServiceNamespace": "dynamodb"
        }
    },   
      "WriteScalingPolicy": {
        "Type": "AWS::ApplicationAutoScaling::ScalingPolicy",
        "Properties": {
            "PolicyName": "WriteAutoScalingPolicy",
            "PolicyType": "TargetTrackingScaling",
            "ScalingTargetId": {
                "Ref": "WriteCapacityScalableTarget"
            },
            "TargetTrackingScalingPolicyConfiguration": {
                "TargetValue": 50,
                "ScaleInCooldown": 60,
                "ScaleOutCooldown": 60,
                "PredefinedMetricSpecification": {
                    "PredefinedMetricType": "DynamoDBWriteCapacityUtilization"
                }
            }
        }
    },

Tried this but not working.

"WriteCapacityScalableTarget": {
   "Type": "AWS::ApplicationAutoScaling::ScalableTarget",
   "Properties": {
       "ResourceId": {
       ...
           "Fn::Join": [
               "/",
               [
                   "table",
                   {
                       "Ref": "DDBTable"
                   },
                   "table",
                   {
                     "Ref": "AnotherTable2"
                   }
               ]
           ]
       },
       ...
   }

1

1 Answers

1
votes

I can of course create scalableTarget again and again but it’s repetitive

Using plain CFN, this is how you have to do it. The reason is that ResourceId is just a string, rather then a list of strings.

The only other alternative in CFN would be to use custom resource or macros. In both cases you would have to develop some lambda function to do automatically the repetitive stuff.