»ECS Task Driver

Name: nomad-driver-ecs

Homepage: https://github.com/hashicorp/nomad-driver-ecs

The ECS task driver plugin for Nomad allows running AWS ECS tasks via Nomad. Allocations for these jobs are scheduled onto Nomad clients like traditional task drivers, however the actual task is executed remotely in AWS ECS. The Nomad client agent manages the remote ECS task like any other local Nomad task: restarting it if it fails, stopping it when requested, etc.

When a Nomad node assigned allocations with ECS tasks is drained, the ECS tasks are not stopped. Instead the replacement allocations reconnect to the original ECS tasks to avoid unnecessary downtime.

If a Nomad node assigned allocations with ECS tasks crashes and is considered down, the replacement allocations for the lost allocations reconnect to the original ECS tasks to avoid unnecessary downtime. If the original crashed Nomad node restarts, it will detect lost allocations and stop monitoring them since a new node has taken over.

»Client Requirements

The AWS ECS Task Driver is not currently built into Nomad and must be downloaded onto the client host in the configured plugin directory.

»Plugin Options

Once the plugin binary is installed, the plugin must be configured in your Nomad client agent's HCL:

plugin "nomad-driver-ecs" {
  config {
    enabled = true

    #  AWS ECS Cluster to run tasks in
    cluster = "nomad-remote-driver-cluster"

    # AWS ECS Region to run tasks in
    region  = "us-east-1"
  }
}
plugin "nomad-driver-ecs" {  config {    enabled = true
    #  AWS ECS Cluster to run tasks in    cluster = "nomad-remote-driver-cluster"
    # AWS ECS Region to run tasks in    region  = "us-east-1"  }}

»Task Configuration

Nomad ECS tasks must first be defined for the ECS cluster. See the Nomad ECS driver demo task for an example ECS task provisioned by Terraform.

Once the ECS task is provisioned, Nomad may run it via a job:

job "nomad-ecs-demo" {
  datacenters = ["dc1"]

  group "ecs-remote-task-demo" {
    restart {
      attempts = 0
      mode     = "fail"
    }

    reschedule {
      delay = "5s"
    }

    task "http-server" {
      driver       = "ecs"
      kill_timeout = "1m" // increased from default to accomodate ECS.

      config {
        task {
          launch_type     = "FARGATE"
          task_definition = "nomad-remote-driver-demo:1"
          network_configuration {
            aws_vpc_configuration {
              assign_public_ip = "ENABLED"
              security_groups  = ["sg-0d647d4c7ce15034f"]
              subnets          = ["subnet-010b03f1a021887ff"]
            }
          }
        }
      }
    }
  }
}
job "nomad-ecs-demo" {  datacenters = ["dc1"]
  group "ecs-remote-task-demo" {    restart {      attempts = 0      mode     = "fail"    }
    reschedule {      delay = "5s"    }
    task "http-server" {      driver       = "ecs"      kill_timeout = "1m" // increased from default to accomodate ECS.
      config {        task {          launch_type     = "FARGATE"          task_definition = "nomad-remote-driver-demo:1"          network_configuration {            aws_vpc_configuration {              assign_public_ip = "ENABLED"              security_groups  = ["sg-0d647d4c7ce15034f"]              subnets          = ["subnet-010b03f1a021887ff"]            }          }        }      }    }  }}
  • config.task stanza defines the configuration of the ECS task:

    • launch_type - The launch type on which to run your task.

    • task_definition - The family and revision (family:revision) or full ARN of the task definition to run.

    • network_configuration - The network configuration for the task (eg awsvpc for FARGATE tasks).

      • aws_vpc_configuration - The VPC subnets and security groups associated with a task.

        • assign_public_ip - Whether the task's elastic network interface receives a public IP address.
        • security_groups - The security groups associated with the task or service.
        • subnets - The subnets associated with the task or service.