fix: switch ECS services to Fargate Spot to reduce cost - #153
Open
Akash29g wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Switch both ECS services (
docanalytics-api-svc,docanalytics-web-svc) from on-demand Fargate to Fargate Spot capacity.Why
Cost Explorer (Charge type = Usage, gross pre-credit) shows Elastic Container Service as the single largest daily line item on the account, running ~$2/day combined with ALB and RDS. With AWS credits nearly exhausted, Fargate Spot gives up to ~70% off the same vCPU/memory pricing for both services, with no code or architecture change required.
Change
infra/ecs.tf→aws_ecs_service.apiandaws_ecs_service.web: replacedlaunch_type = "FARGATE"with acapacity_provider_strategyblock (FARGATE_SPOT, weight 1, base 1).aws_ecs_cluster_capacity_providers.mainso the cluster allows Spot capacity, with a matching default strategy.Scope / Safety
desired_count = 1and thelifecycle { ignore_changes = [task_definition, desired_count] }blocks are unchanged, so the existing CI/CD deploy flow (deploy.yml) is unaffected.desired_count = 1this may cause a brief (seconds-level) blip, not sustained downtime.deploy.ymldoes not run Terraform, so this change requires a manualterraform applyfrominfra/after merge — it will not take effect on push alone.How to verify
terraform planlocally shows changes limited to the 2 services + 1 new capacity-provider resource — no destroys.terraform apply: ECS console → Services → both services showCAPACITY PROVIDER: FARGATE_SPOTandRUNNINGcount stays at 1 throughout the rollout.