Skip to content

Commit 31edb1c

Browse files
authored
Merge pull request #6 from mpon/feature/fargate_spot
Support Fargate Spot
2 parents f526185 + ac8492d commit 31edb1c

File tree

12 files changed

+46
-11
lines changed

12 files changed

+46
-11
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This repository is just an example, but we are aiming for a level that can be us
77
You can use this repository to try creating your own AWS infrastructure!
88

99
- [x] VPC
10-
- [x] ECS on Fargate
10+
- [x] ECS on Fargate and Fargate Spot with capacity provider
1111
- [x] ECS Application Auto Scaling by Target Tracking Scaling Policies
1212
- [x] ECS Scheduled Task
1313
- [x] CodePipline triggerd by GitHub
@@ -18,6 +18,7 @@ You can use this repository to try creating your own AWS infrastructure!
1818
![structure](docs/aws.drawio.svg)
1919
![pipeline](docs/pipeline.drawio.svg)
2020
![ecs](docs/ecs.png)
21+
![fargate_spot](docs/fargate_spot.png)
2122
![scheduled_task](docs/scheduled_task.png)
2223
![codepipeline](docs/codepipeline.png)
2324

docs/fargate_spot.png

157 KB
Loading

terraform/common/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
init:
2+
tfenv install
23
terraform init \
34
-backend-config="bucket=${TF_VAR_remote_backend}" \
45
-backend-config="region=${AWS_DEFAULT_REGION}"

terraform/dev/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
init:
2+
tfenv install
23
terraform init \
34
-backend-config="bucket=${TF_VAR_remote_backend}" \
45
-backend-config="region=${AWS_DEFAULT_REGION}"

terraform/prod/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
init:
2+
tfenv install
23
terraform init \
34
-backend-config="bucket=${TF_VAR_remote_backend}" \
45
-backend-config="region=${AWS_DEFAULT_REGION}"

terraform/prod/ecs_cluster.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resource "aws_ecs_cluster" "cluster" {
2-
name = "${local.env}-cluster"
2+
name = "${local.env}-cluster"
3+
capacity_providers = ["FARGATE", "FARGATE_SPOT"]
34
}
45

56
module "ecs_task_execution_iam" {

terraform/prod/ecs_service_api.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ resource "aws_ecs_service" "api" {
4747
cluster = aws_ecs_cluster.cluster.id
4848
task_definition = aws_ecs_task_definition.api.arn
4949
desired_count = 0 # desired_count will be updated by autoscaling
50-
launch_type = "FARGATE"
5150

5251
load_balancer {
5352
target_group_arn = aws_lb_target_group.api_blue.arn
@@ -64,6 +63,17 @@ resource "aws_ecs_service" "api" {
6463
type = "CODE_DEPLOY"
6564
}
6665

66+
capacity_provider_strategy {
67+
capacity_provider = "FARGATE"
68+
weight = 2
69+
base = 1
70+
}
71+
72+
capacity_provider_strategy {
73+
capacity_provider = "FARGATE_SPOT"
74+
weight = 1
75+
}
76+
6777
lifecycle {
6878
# This parameter will be chaned by CodeDeploy
6979
ignore_changes = [
@@ -86,8 +96,8 @@ module "api_autoscaling" {
8696

8797
cluster_name = aws_ecs_cluster.cluster.name
8898
service_name = aws_ecs_service.api.name
89-
min_capacity = 1
90-
max_capacity = 1
99+
min_capacity = 3
100+
max_capacity = 6
91101
cpu_target_value = 60
92102
role_arn = data.terraform_remote_state.common.outputs.ecs_application_autoscaling_role_arn
93103
}

terraform/prod/ecs_service_web.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ resource "aws_ecs_service" "web" {
4747
cluster = aws_ecs_cluster.cluster.id
4848
task_definition = aws_ecs_task_definition.web.arn
4949
desired_count = 0 # desired_count will be updated by autoscaling
50-
launch_type = "FARGATE"
5150

5251
load_balancer {
5352
target_group_arn = aws_lb_target_group.web_blue.arn
@@ -64,6 +63,17 @@ resource "aws_ecs_service" "web" {
6463
type = "CODE_DEPLOY"
6564
}
6665

66+
capacity_provider_strategy {
67+
capacity_provider = "FARGATE"
68+
weight = 2
69+
base = 1
70+
}
71+
72+
capacity_provider_strategy {
73+
capacity_provider = "FARGATE_SPOT"
74+
weight = 1
75+
}
76+
6777
lifecycle {
6878
# This parameter will be chaned by CodeDeploy
6979
ignore_changes = [
@@ -86,8 +96,8 @@ module "web_autoscaling" {
8696

8797
cluster_name = aws_ecs_cluster.cluster.name
8898
service_name = aws_ecs_service.web.name
89-
min_capacity = 1
90-
max_capacity = 1
99+
min_capacity = 3
100+
max_capacity = 6
91101
cpu_target_value = 60
92102
role_arn = data.terraform_remote_state.common.outputs.ecs_application_autoscaling_role_arn
93103
}

terraform/stg/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
init:
2+
tfenv install
23
terraform init \
34
-backend-config="bucket=${TF_VAR_remote_backend}" \
45
-backend-config="region=${AWS_DEFAULT_REGION}"

terraform/stg/ecs_cluster.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resource "aws_ecs_cluster" "cluster" {
2-
name = "${local.env}-cluster"
2+
name = "${local.env}-cluster"
3+
capacity_providers = ["FARGATE", "FARGATE_SPOT"]
34
}
45

56
module "ecs_task_execution_iam" {

0 commit comments

Comments
 (0)