Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bugre/21371773224e71d9255a008fcdbf0cd5 to your computer and use it in GitHub Desktop.

Select an option

Save bugre/21371773224e71d9255a008fcdbf0cd5 to your computer and use it in GitHub Desktop.

Revisions

  1. @toricls toricls created this gist Aug 5, 2019.
    70 changes: 70 additions & 0 deletions Time-based-auto-scaling-on-fargate.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    ### Set parameters

    ```shell
    $ export ECS_CLUSTER_NAME={YOUR_ECS_CLUSTER_NAME}
    $ export ECS_SERVICE_NAME={YOUR_ECS_SERVICE_NAME}
    ```

    ### RegisterScalableTarget

    ```shell
    $ aws application-autoscaling register-scalable-target --service-namespace ecs \
    --scalable-dimension ecs:service:DesiredCount \
    --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \
    --min-capacity 1 \
    --max-capacity 3
    ```

    ### PutScheduledAction

    ```shell
    $ export SCALE_OUT_ACTION_NAME=fargate-time-based-scale-out

    # configure scaling out
    $ aws application-autoscaling put-scheduled-action --service-namespace ecs \
    --scalable-dimension ecs:service:DesiredCount \
    --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \
    --scheduled-action-name ${SCALE_OUT_ACTION_NAME} \
    --schedule "cron(50 23 * * ? *)" \ # every day at 8:50am JST
    --scalable-target-action MinCapacity=3,MaxCapacity=10
    ```

    ```shell
    $ export SCALE_IN_ACTION_NAME=fargate-time-based-scale-in

    # configure scaling in
    $ aws application-autoscaling put-scheduled-action --service-namespace ecs \
    --scalable-dimension ecs:service:DesiredCount \
    --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \
    --scheduled-action-name ${SCALE_IN_ACTION_NAME} \
    --schedule "cron(10 9 * * ? *)" \ # every day at 6:10pm JST
    --scalable-target-action MinCapacity=1,MaxCapacity=1
    ```

    ### DeleteScheduledAction

    ```shell
    $ aws application-autoscaling delete-scheduled-action --service-namespace ecs \
    --scheduled-action-name ${SCALE_OUT_ACTION_NAME} \
    --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \
    --scalable-dimension ecs:service:DesiredCount
    ```

    ```shell
    $ aws application-autoscaling delete-scheduled-action --service-namespace ecs \
    --scheduled-action-name ${SCALE_IN_ACTION_NAME} \
    --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \
    --scalable-dimension ecs:service:DesiredCount
    ```


    ### DescribeScheduledActions

    ```shell
    $ aws application-autoscaling describe-scheduled-actions --service-namespace ecs \
    --scheduled-action-names ${SCALE_IN_ACTION_NAME} ${SCALE_OUT_ACTION_NAME}
    ```

    ### See also

    https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scheduled-scaling.html