Skip to content

Commit

Permalink
Configure Fargate Spot tasks (#7)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zaro0508 authored Dec 12, 2024
1 parent 7c51f57 commit c36caf5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/service_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c36caf5

Please sign in to comment.