Running Windows images on Amazon ECS

Running Windows images on Amazon ECS
Photo by chuttersnap on Unsplash

What is ECS?

Amazon Elastic Container Service (Amazon ECS) is a highly scalable, high-performance container orchestration service that supports Docker containers and allows you to easily run and scale containerized applications on AWS. Amazon ECS eliminates the need for you to install and operate your own container orchestration software, manage and scale a cluster of virtual machines, or schedule containers on those virtual machines.

In a nutshell, it is a service that allows you to spin up Docker containers in order to perform specific tasks, e.g. image processing, sending out emails etc.

What is an ECS task?

An AWS Elastic Container Service (ECS) task is a group of containers that are scheduled to run on a single Amazon Elastic Container Service (ECS) cluster. Tasks are defined in a task definition, which is a JSON file that specifies the containers that make up the task, as well as the resources that the task needs, such as CPU, memory, and storage.

Tasks can be scheduled to run in one of two modes - Fargate and Amazon EC2. For now, we will talk about using Amazon EC2 (as during my initial investigation a few years ago there was no support for Windows containers on Fargate!)

Why would I use ECS tasks?

Here are some of the benefits of using AWS ECS tasks:

  • Ease of use: AWS ECS tasks make it easy to run containers on Amazon ECS. You don't need to worry about managing the underlying infrastructure.
  • Scalability: AWS ECS tasks can be scaled up or down to meet demand. This makes them ideal for running applications that experience spikes in traffic.
  • Reliability: AWS ECS tasks are reliable. If an Amazon EC2 instance fails, Amazon ECS will automatically reschedule the task on another instance.

If you are looking for a way to run containers on Amazon ECS, AWS ECS tasks are a great option. They are easy to use, scalable, and reliable.

How to create tasks?

To create an AWS ECS task, you first need to create a task definition. You can do this using the AWS Management Console, the AWS CLI, or the Amazon ECS API. Once you have created a task definition, you can run the task using the AWS Management Console, the AWS CLI, or the Amazon ECS API.

When you run a task, Amazon ECS will schedule the task on one or more Amazon EC2 instances in the cluster. The number of Amazon EC2 instances that are used to run the task depends on the number of containers in the task and the resources that each container needs.

Once a task is running, you can monitor its status using the AWS Management Console, the AWS CLI, or the Amazon ECS API. You can also stop, pause, and delete tasks using the same methods.

Why is my task stuck in the PENDING state?

There are a number of reasons why an ECS task might be stuck in a pending state. Here are the most common reasons:

  • The task definition is invalid. Make sure that your task definition is valid and that it specifies all of the required fields.
  • The task is using a resource that is not available. Make sure that the task has access to the resources that it needs, such as CPU, memory, and storage.
  • The task is trying to connect to a network that is not available. Make sure that the task has access to the network that it needs.
  • The task is trying to access a service that is not available. Make sure that the task can access the services that it needs.
  • The task is waiting for another task to complete. If your task is dependent on another task, make sure that the other task has been completed before launching your task.
  • The task is waiting for manual intervention. If your task is waiting for a manual intervention, such as a user to approve the task, make sure that the intervention has been completed before launching your task.

However, in my case, it seemed like there was not enough resource allocated to the task, so it would be constantly trying to spin up the container unsuccessfully!

How to check on progress?

From a high-level view, you can use the AWS Management Console to check on progress. You will see whether the ECS task is running or not. You can also leverage the CLI and APIs that AWS provides in order to have programmatic access to the progress of a task.

You will also be able to leverage CloudWatch logs if they are enabled, as there are multiple log groups that are created for ECS tasks.

What is a bastion host?

A bastion host is a server that is specifically designed to provide access to other servers in a network. Bastion hosts are typically located in a public-facing subnet, which allows them to be accessed from the internet. This makes them ideal for providing access to servers that are located in private subnets, which are not accessible from the internet.

Bastion hosts are useful in AWS because they can help to improve the security of your network. By using a bastion host, you can reduce the number of servers that are exposed to the internet. This can help to protect your servers from attacks.

In addition, bastion hosts can be used to implement security best practices, such as least privilege. By using a bastion host, you can restrict access to other servers to only those users who need it. This can help to protect your servers from unauthorized access.

Here are some of the benefits of using a bastion host:

🔐
Increased security: Bastion hosts can help to increase the security of your network by providing a single point of access to other servers. This can help to reduce the number of servers that are exposed to the internet and can make it more difficult for attackers to gain access to your network.
🙌
Improved efficiency: Bastion hosts can help to improve the efficiency of your network by centralizing access to other servers. This can make it easier for administrators to manage and troubleshoot servers.
💸
Reduced costs: Bastion hosts can help to reduce the costs of your network by reducing the number of servers that need to be maintained.

Bastion hosts are great if you are placing your ECS tasks that process internal workloads into a private subnet within your VPC.  Or, you may have some ECS tasks in a private subnet for hosting a website, where they will be behind an Application Load Balancer (ALB).


Workarounds

It is always a tricky process to ensure you are using your ECS tasks efficiently (and not overpaying for unused resources). Here are some tips:

🖥️
Start with a small compute level: When you are first deploying your task, it is a good idea to start with a small compute level. This will help you to avoid overprovisioning resources and will help you to keep costs down. However, don't go too low or the container will not boot up... 👀
🔎
Monitor your task: Once your task is running, it is important to monitor it to make sure that it is using the correct amount of resources. If you notice that your task is using more resources than it needs, you can increase the compute level. If you notice that your task is using fewer resources than it needs, you can decrease the compute level.
⚖️
Use autoscaling: An autoscale is a tool that can help you automatically adjust the compute level of your task based on demand. This can help you to ensure that your task is always using the correct amount of resources and can help you to keep costs down.