From 897414d9f5481317af1fef3b85d0d905bb21cdf0 Mon Sep 17 00:00:00 2001
From: Khai Do <zaro0508@gmail.com>
Date: Wed, 11 Dec 2024 13:11:15 -0800
Subject: [PATCH 1/2] 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 26775a3..32b888d 100644
--- a/src/service_stack.py
+++ b/src/service_stack.py
@@ -129,6 +129,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

From 19d0cb5c9c932075da627bd65621214a0167366d Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Wed, 11 Dec 2024 21:16:57 +0000
Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 src/service_stack.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/service_stack.py b/src/service_stack.py
index 32b888d..a124d9e 100644
--- a/src/service_stack.py
+++ b/src/service_stack.py
@@ -133,12 +133,12 @@ def _get_secret(scope: Construct, id: str, name: str) -> sm.Secret:
             capacity_provider_strategies=[
                 ecs.CapacityProviderStrategy(
                     capacity_provider="FARGATE",
-                    base=1,       # At least 1 task will be run by 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
-                )
+                    weight=1,  # The remain task will be run by FARGATE_SPOT
+                ),
             ],
         )