Search code examples
amazon-web-servicesdockeramazon-ecswindows-containeraws-auto-scaling

AWS ECS Auto Scaling for Windows Containers


We have couple of (> 5) windows framework 4.8 .Net MVC Web application workloads hosted in an Multi-AZ ECS cluster (EC2 type :Windows) exposed outside by an ALB. All of those applications are working fine for quite a period. Now its required to introduce auto scaling for these applications selectively (Out of 5, 3 needs scaling out/in) . We are thinking of leveraging below two features together to achieve this .

  1. ECS Service auto scaling to scale up each container instances(task level).

  2. ECS cluster auto scaling using ECS capacity providers in an EC2 Instance level. Which provides space for containers spun up by task in Step 1.

My question is ,is this achievable?, or is this the right approach for Windows Containers? . Why I am stressing Windows container is because AWS ECS lack many feature compared to Linux containers , for example We can't set Container memory Soft limit(memory reservation) but should mention a hard limit(memory) while configuring the task itself, which I think is a major limitation .

if this is not achievable what are the options ? We are not in a position to move to EKS now and obviously there is no Windows support for Fargate.


Solution

  • In order to disable the hard memory restriction for windows containers set "ECS_ENABLE_MEMORY_UNBOUNDED_WINDOWS_WORKAROUND" environment variable to true on launch template UserData .

    1. AWS Launch template user data
    <powershell>
    [Environment]::SetEnvironmentVariable("ECS_RESERVED_MEMORY",256, "Machine") 
    [Environment]::SetEnvironmentVariable("ECS_ENABLE_MEMORY_UNBOUNDED_WINDOWS_WORKAROUND", $true, "Machine") 
    [Environment]::SetEnvironmentVariable("ECS_ENABLE_CPU_UNBOUNDED_WINDOWS_WORKAROUND", $true, "Machine") 
    Initialize-ECSAgent -Cluster <clustername>-EnableTaskIAMRole -LoggingDrivers '["json-file","awslogs"]' 
    </powershell>
    
    1. In task definition Skip Memory hard limit and provide Soft limit(Reservation) which will be ignore by the agent.

    Agent version should be >=1.32.1 (Greater the better)