Tuesday, July 29, 2025

ECS Service with Auto Scaling For High Performance & Cost Efficiency | Overview.

ECS service with Auto Scaling For High Performance & Cost Efficiency - Overview. 

Scope:

  • Intro,
  • How ECS Service Auto Scale Works,
  • Architecture,
  • Prerequisites,
  • Key Concepts,
  • How to Set It Up (CLI & Console),
  • Register the Service with Application Auto Scaling (CLI),
  • Create Scaling Policy (CLI),
  • Monitoring,
  • Final thoughts.

Intro:

  • ECS Service Auto Scaling automatically adjusts the desired count of tasks in twtech ECS service based on CloudWatch alarms.
  • This helps maintain performance and cost-efficiency, especially for variable workloads.

 How ECS Service Auto Scale Works:

  •         ECS Service runs tasks using a task definition.
  •         Auto Scaling changes the desired task count (not CPU/memory of the container).
  •         CloudWatch Alarms monitor metrics like CPU or memory usage.
  •         Scaling Policies define when and how to scale-in or Scale-out.
Architecture

Prerequisites:

  •         ECS cluster and service ( with severless-Fargate or EC2-backed).
  •         IAM role with ecs:UpdateService, cloudwatch:*, and application-autoscaling:*.
  •         Metrics like CPU Utilization or custom CloudWatch metrics Minitored.

 Key Concepts:

Term

Description

Target Tracking.

Scales to maintain a target metric (e.g., 50% CPU). Most common.

Step Scaling.

Scales based on thresholds and step adjustments.

Scheduled Scaling.

Scales at specific times (e.g., nightly).

 How to Set It Up (CLI or Console)

1. Register the Service with Application Auto Scaling.

# bash
 aws application-autoscaling register-scalable-target \
  --service-namespace twtech-ecs-ns \
  --resource-id service/twtech-ecs-cluster/twtechsprings-ecs-service \
  --scalable-dimension ecs:service:DesiredCount \
  --min-capacity 2 \
  --max-capacity 10

2. Create Scaling Policy

# bash
aws application-autoscaling put-scaling-policy \
  --service-namespace twteh-ecs-ns \
  --resource-id service/twtech-ecs-cluster/twtechspringapp-ecs-service \
  --scalable-dimension ecs:service:DesiredCount \
  --policy-name cpu-target-tracking \
  --policy-type TargetTrackingScaling \
  --target-tracking-scaling-policy-configuration file://policy.json

# policy.json example:

# json
{
  "TargetValue": 50.0,
  "PredefinedMetricSpecification": {
    "PredefinedMetricType": "ECSServiceAverageCPUUtilization"
  },
  "ScaleInCooldown": 60,
  "ScaleOutCooldown": 60
}

 Monitoring:

  •         Use CloudWatch dashboards to visualize CPU, memory, and task count.
  •         Use ECS console or CLI (describe-services) to see desired vs. running task counts.

 twtech Final thoughts:

  •         Auto Scaling only adjusts the desired count—twtech tasks definition’s CPU/memory don’t change.
  •         Works with both Fargate and EC2 launch types.
  •         Scaling down to 0 is allowed but be careful with cold starts.



No comments:

Post a Comment

Amazon EventBridge | Overview.

Amazon EventBridge - Overview. Scope: Intro, Core Concepts, Key Benefits, Link to official documentation, Insights. Intro: Amazon EventBridg...