services.x-scaling

services:
  serviceA:
    x-scaling:
      Range: str
      ScheduledActions: []
      TargetScaling:
        CpuTarget: float
        RamTarget: float

Range

Range, defines the minimum and maximum number of containers you will have running in the cluster.

#Syntax
# Range: "<min>-<max>"
# Example
Range: "1-21"

ScheduledActions

The ScheduledActions is a list of ScheduledActions as created and defined by AwsCommunity::ApplicationAutoscaling::ScheduledAction allowing to create scheduled autoscaling activities to change the MinCapacity and MaxCapacity of your ECS Service.

This allows for great flexibility and costs savings to ensure you always get all the capacity you need when you need it, and rely at the same time on otherwise defined scaling policies.

Example

In the following example, Monday to Friday, for 1h, we change the scaling max & min.

services:
  my-service:
    x-scaling:
      Range: 1-10
      ScheduledActions:
        - Timezone: Europe/London
          Schedule: cron(45 2 ? * MON-FRIN)
          ScheduledActionName: Scale.Up
          ScalableTargetAction:
            MinCapacity: 2
            MaxCapacity: 4
          MacroParameters:
            AddServiceName: true
        - Timezone: Europe/London
          Schedule: cron(45 3 ? * MON-FRIN)
          ScheduledActionName: Scale.Down
          ScalableTargetAction:
            MinCapacity: 1
            MaxCapacity: 2

TargetScaling

Allows you to define target scaling for the service based on CPU/RAM.

target scaling syntax reference
x-scaling:
  Range: "1-10"
  TargetScaling:
    CpuTarget: number (percentage, i.e. 75.0)
    MemoryTarget: number (percentage, i.e. 80.0)
    ScaleInCooldown: int (ie. 60)
    ScaleOutCooldown: int (ie. 60)
    DisableScaleIn: boolean (True/False)

CpuTarget / RamTarget

Defines the CPU percentage that we want the service to be under. ECS will automatically create and adapt alarms to scale the service in/out so long as the average CPU usage remains beneath that value.

Attention

Note that setting both should not be set at the same time, as you might end up into a racing condition.

ScaleInCooldown / ScaleOutCooldown

This allows you to define the Cooldown between scaling activities in order to limit drastic changes.

Hint

These are set only for the CPU and RAM targets, no impact on other scaling such as SQS.

DisableScaleIn

Default: False

Same as the original Property in the CFN definition, this will deny a service to scale in after it has scaled-out for applications that do not support to scale-in.

Hint

If you define multiple services within the same family , the lowest value for CPU/RAM and highest for scale in/out are used in order to minimize the impact and focus on the weakest point.

Tip

For SQS Based scaling using step scaling, refer to SQS Scaling Documentation.

JSON Schema

Model

services.x-scaling specification

services.x-scaling

The services.x-scaling specification for ComposeX

type

object

properties

  • Range

type

string

  • TargetScaling

#/definitions/TargetScalingDef

  • ScheduledActions

#/definitions/ScheduledActions

definitions

  • TargetScalingDef

type

object

properties

  • CpuTarget

Percentage of CPU usage to track and scale services accordingly

type

integer

maximum

100.0

minimum

0.1

  • MemoryTarget

Percentage of RAM usage to track and scale services accordingly

type

integer

maximum

100.0

minimum

0.1

  • ScaleInCooldown

Lapse of time before scaling in since last scaling activity

type

integer

default

300

  • ScaleOutCooldown

Lapse of time before scaling out since last scaling activity.

type

integer

default

60

  • DisableScaleIn

Whether the scaling in should be disabled or not.

type

boolean

default

False

additionalProperties

False

oneOf

allOf

not

not

  • ScheduledActions

type

array

items

#/definitions/ScheduledAction

  • ScheduledAction

type

object

properties

  • MacroParameters

type

object

properties

  • AddServiceName

Automatically adds the ScheduledActionName to make it unique

type

boolean

  • AddRandomId

Automatically adds a short ID to the ScheduledActionName to make it unique

type

boolean

additionalProperties

False

  • EndTime

type

string

  • ScalableTargetAction

type

object

properties

  • MaxCapacity

type

number

minimum

0

  • MinCapacity

type

number

minimum

0

additionalProperties

False

  • Schedule

type

string

  • ScheduledActionName

type

string

pattern

^[a-zA-Z0-9-_\.]+

  • StartTime

type

string

  • Timezone

type

string

default

UTC

additionalProperties

False

Definition

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "id": "services.x-scaling",
  "$id": "services.x-scaling.spec.json",
  "type": "object",
  "title": "services.x-scaling specification",
  "description": "The services.x-scaling specification for ComposeX",
  "properties": {
    "Range": {
      "type": "string"
    },
    "TargetScaling": {
      "$ref": "#/definitions/TargetScalingDef"
    },
    "ScheduledActions": {
      "$ref": "#/definitions/ScheduledActions"
    }
  },
  "definitions": {
    "TargetScalingDef": {
      "type": "object",
      "additionalProperties": false,
      "oneOf": [
        {
          "allOf": [
            {
              "not": {
                "required": [
                  "CpuTarget"
                ]
              }
            },
            {
              "not": {
                "required": [
                  "MemoryTarget"
                ]
              }
            }
          ]
        },
        {
          "required": [
            "CpuTarget"
          ]
        },
        {
          "required": [
            "MemoryTarget"
          ]
        }
      ],
      "properties": {
        "CpuTarget": {
          "type": "integer",
          "maximum": 100.0,
          "minimum": 0.1,
          "description": "Percentage of CPU usage to track and scale services accordingly"
        },
        "MemoryTarget": {
          "type": "integer",
          "description": "Percentage of RAM usage to track and scale services accordingly",
          "maximum": 100.0,
          "minimum": 0.1
        },
        "ScaleInCooldown": {
          "type": "integer",
          "default": 300,
          "description": "Lapse of time before scaling in since last scaling activity"
        },
        "ScaleOutCooldown": {
          "type": "integer",
          "default": 60,
          "description": "Lapse of time before scaling out since last scaling activity."
        },
        "DisableScaleIn": {
          "type": "boolean",
          "default": false,
          "description": "Whether the scaling in should be disabled or not."
        }
      }
    },
    "ScheduledActions": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/ScheduledAction"
      }
    },
    "ScheduledAction": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "MacroParameters": {
          "type": "object",
          "additionalProperties": false,
          "oneOf": [
            {
              "required": [
                "AddServiceName"
              ]
            },
            {
              "required": [
                "AddRandomId"
              ]
            }
          ],
          "properties": {
            "AddServiceName": {
              "type": "boolean",
              "description": "Automatically adds the ScheduledActionName to make it unique"
            },
            "AddRandomId": {
              "type": "boolean",
              "description": "Automatically adds a short ID to the ScheduledActionName to make it unique"
            }
          }
        },
        "EndTime": {
          "type": "string"
        },
        "ScalableTargetAction": {
          "type": "object",
          "additionalProperties": false,
          "anyOf": [
            {
              "required": [
                "MaxCapacity"
              ]
            },
            {
              "required": [
                "MinCapacity"
              ]
            }
          ],
          "properties": {
            "MaxCapacity": {
              "type": "number",
              "minimum": 0
            },
            "MinCapacity": {
              "type": "number",
              "minimum": 0
            }
          }
        },
        "Schedule": {
          "type": "string"
        },
        "ScheduledActionName": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9-_\\.]+"
        },
        "StartTime": {
          "type": "string"
        },
        "Timezone": {
          "type": "string",
          "default": "UTC"
        }
      }
    }
  }
}