<p>I am trying to create a certain kind of networking infrastructure, and have been looking at Amazon ECS and Kubernetes. However I am not quite sure if these systems do what I am actually seeking, or if I am contorting them to something else. If I could describe my task at hand, could someone please verify if Amazon ECS or Kubernetes actually will aid me in this effort, and this is the right way to think about it?</p>

<p>What I am trying to do is on-demand single-task processing on an AWS instance. What I mean by this is, I have a resource heavy application which I want to run in the cloud and have process a chunk of data submitted by a user. I want to submit a this data to be processed on the application, have an EC2 instance spin up, process the data, upload the results to S3, and then shutdown the EC2 instance.</p>

<p>I have already put together a functioning solution for this using Simple Queue Service, EC2 and Lambda. But I am wondering would ECS or Kubernetes make this simpler? I have been going through the ECS documenation and it seems like it is not very concerned with starting up and shutting down instances. It seems like it wants to have an instance that is constantly running, then docker images are fed to it as task to run. Can Amazon ECS be configured so if there are no task running it automatically shuts down all instances?</p>

<p>Also I am not understanding how exactly I would submit a specific chunk of data to be processed. It seems like "Tasks" as defined in Amazon ECS really correspond to a single Docker container, not so much what kind of data that Docker container will process. Is that correct? So would I still need to feed the data-to-be-processed into the instances via simple queue service, or other? Then use Lambda to poll those queues to see if they should submit tasks to ECS?</p>

<p>This is my naive understanding of this right now, if anyone could help me understand the things I've described better, or point me to better ways of thinking about this it would be appreciated.</p>

rygo6
<p>This is a complex subject and many details for a good answer depend on the exact requirements of your domain / system. So the following information is based on the very high level description you gave.</p>

<p>A lot of the features of ECS, kubernetes etc. are geared towards allowing a distributed application that acts as a single service and is horizontally scalable, upgradeable and maintanable. This means it helps with unifying service interfacing, load balancing, service reliability, zero-downtime-maintenance, scaling the number of worker nodes up/down based on demand (or other metrics), etc. </p>

<p>The following describes a high level idea for a solution for your use case with kubernetes (which is a bit more versatile than AWS ECS). </p>

<p>So for your use case you could set up a kubernetes cluster that runs a distributed event queue, for example an Apache Pulsar cluster, as well as an application cluster that is being sent queue events for processing. Your application cluster size could scale automatically with the number of unprocessed events in the queue (<a href="https://docs.bitnami.com/kubernetes/how-to/configure-autoscaling-custom-metrics/" rel="nofollow noreferrer">custom pod autoscaler</a>). The cluster infrastructure would be configured to scale automatically based on the number of scheduled pods (pods reserve capacity on the infrastructure).</p>

<p>You would have to make sure your application can run in a stateless form in a container.</p>

<p>The main benefit I see over your current solution would be cloud provider independence as well as some general benefits from running a containerized system: 1. not having to worry about the exact setup of your EC2-Instances in terms of operating system dependencies of your workload. 2. being able to address the processing application as a single service. 3. Potentially increased reliability, for example in case of errors.</p>

<p>Regarding your exact questions:</p>

<blockquote>
  <p>Can Amazon ECS be configured so if there are no task running it
  automatically shuts down all instances?</p>
</blockquote>

<p>The keyword here is autoscaling. Note that there are two levels of scaling: 1. Infrastructure scaling (number of EC2 instances) and application service scaling (number of application containers/tasks deployed). ECS infrastructure scaling works based on EC2 autoscaling groups. For more info see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/scale_cluster.html" rel="nofollow noreferrer">this link</a> . For application service scaling and serverless ECS (Fargate) see <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html" rel="nofollow noreferrer">this link</a>.</p>

<blockquote>
  <p>Also I am not understanding how exactly I would submit a specific
  chunk of data to be processed. It seems like "Tasks" as defined in
  Amazon ECS really correspond to a single Docker container, not so much
  what kind of data that Docker container will process. Is that correct?</p>
</blockquote>

<p>A "<a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definitions.html" rel="nofollow noreferrer">Task Definition</a>" in ECS is describing how one or multiple docker containers can be deployed for a purpose and what its environment / limits should be. A task is a single instance that is run in a "Service" which itself can deploy a single or multiple tasks. Similar concepts are Pod and Service/Deployment in kubernetes.</p>

<blockquote>
  <p>So would I still need to feed the data-to-be-processed into the
  instances via simple queue service, or other? Then use Lambda to poll
  those queues to see if they should submit tasks to ECS?</p>
</blockquote>

<p>A queue is always helpful in decoupling the service requests from processing and to make sure you don't lose requests. It is not required if your application service cluster can offer a service interface and process incoming requests directly in a reliable fashion. But if your application cluster has to scale up/down frequently that may impact its ability to reliably process.</p>
