[awscli][Terraform]Fargate Spot 適用の流れ


・base(必ず動いてほしいタスク数)
・weight(タスクが増える際にどの比率で増やしていくかの対比)

  • awscliで適用
aws --profile=hoge --region=ap-northeast-1 ecs update-service \
     --capacity-provider-strategy capacityProvider=FARGATE,base=0,weight=0  capacityProvider=FARGATE_SPOT,base=1,weight=1 \
     --cluster hoge \
     --service hoge \
     --force-new-deployment
  • Terraformで差分変更
~省略~
#launch_type                        = "FARGATE" #コメントアウト

# 追加
capacity_provider_strategy {
  base              = 0
  capacity_provider = "FARGATE"
  weight            = 0
}
capacity_provider_strategy {
  base              = 1
  capacity_provider = "FARGATE_SPOT"
  weight            = 1
}

deployment_circuit_breaker {
  enable   = true
  rollback = true
}

deployment_controller {
  type = "ECS"
}
  • ECS Scheduled Taskの場合
resource "aws_ecs_cluster" "hoge" {
  name = "hoge"
  capacity_providers = [
    "FARGATE",
    "FARGATE_SPOT",
  ]

#追加
  default_capacity_provider_strategy {
    capacity_provider = "FARGATE_SPOT"
    base              = "1"
    weight            = "1"
  }
}
  • cloudwatch_event_target.tf
ecs_target {
  launch_type         = "" #空白
  task_count          = 1
  task_definition_arn = "arn:aws:ecs:xxxxxxx:xxxxxxxxxxx:task-definition/hoge"
  #platform_version    = "1.4.0" #コメントアウト

EventBridgeで以下のようになっていればOK。

Was this helpful?

0 / 0

コメントを残す 0

Your email address will not be published. Required fields are marked *