From c36caf507da1ebe28a07ec7aa980fcb0fb044cd4 Mon Sep 17 00:00:00 2001 From: Khai Do <3697686+zaro0508@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:05:19 -0800 Subject: [PATCH] Configure Fargate Spot tasks (#7) 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