From f26419dcf9860f471b4464ef1a46a0cb91e04ea9 Mon Sep 17 00:00:00 2001 From: Khai Do Date: Wed, 11 Dec 2024 13:21:00 -0800 Subject: [PATCH] Configure Fargate Spot tasks To reduce costs we setup ECS to deploy Fargate Spot tasks along with on demand task. The idea is to ensure that there is at least one fargate on demand task for stability while all other tasks are run with spot tasks for cost efficiency. --- src/service_stack.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/service_stack.py b/src/service_stack.py index 19319b7..f029392 100644 --- a/src/service_stack.py +++ b/src/service_stack.py @@ -152,6 +152,17 @@ def _get_secret(scope: Construct, id: str, name: str) -> sm.Secret: ) ], ), + # Ensure at least one on demand task and the remaining should be spot tasks + capacity_provider_strategies=[ + ecs.CapacityProviderStrategy( + capacity_provider="FARGATE", + base=1, # At least 1 task will be run by FARGATE + ), + ecs.CapacityProviderStrategy( + capacity_provider="FARGATE_SPOT", + weight=1, # The remain task will be run by FARGATE_SPOT + ), + ], ) # Setup AutoScaling policy