1

I'm triying to implement solution for reverse-proxy service using Traefik v1 (1.7) and ECS one-off tasks as backends, as described in this SO question. Routing should by dynamic - requests to /user/1234/* path should go to the ECS task, running with the appropriate docker labels:

  docker_labels = {
    traefik.frontend.rule = "Path:/user/1234"
    traefik.backend       = "trax1"
    traefik.enable        = "true"
  }

So far this setup works fine, but I need create one ECS task definition per one running task, because the docker labels are the property of ECS TaskDefinition, not the ECS task itself. Is it possible to create only one TaskDefinition and pass Traefik rules in ECS task tags, within task key/value properties?

This will require some modification in Traefik source code, are the any other available options or ways this should be implemented, that I've missed, like API Gateway or Lambda@Edge? I have no experience with those technologies, real-world examples are more then welcome.

mva
  • 384
  • 1
  • 5
  • 12

1 Answers1

0

Solved by using Traefik REST API provider. External component, which runs the one-off tasks, can discover task internal IP and update Traefik configuration on-fly by pair traefik.frontend.rule = "Path:/user/1234" and task internal IP:port values in backends section

It should GET the Traefik configuration first from /api/providers/rest endpoint, remove or add corresponding part (if task was stopped or started), and update Traefik configuration by PUT method to the same endpoint.

{
  "backends": {
    "backend-serv1": {
      "servers": {
        "server-service-serv-test1-serv-test-4ca02d28c79b": {
          "url": "http://172.16.0.5:32793"
        }
      }
    },
    "backend-serv2": {
      "servers": {
        "server-service-serv-test2-serv-test-279c0ba1959b": {
          "url": "http://172.16.0.5:32792"
        }
      }
    }
  },
  "frontends": {
    "frontend-serv1": {
      "entryPoints": [
        "http"
      ],
      "backend": "backend-serv1",
      "routes": {
        "route-frontend-serv1": {
          "rule": "Path:/user/1234"
        }
      }
    },
    "frontend-serv2": {
      "entryPoints": [
        "http"
      ],
      "backend": "backend-serv2",
      "routes": {
        "route-frontend-serv2": {
          "rule": "Path:/user/5678"
        }
      }
    }
  }
}
mva
  • 384
  • 1
  • 5
  • 12