Amazon ECS in Action: How AWS's Container Service Helps You Scale and Optimize Your Applications
Are you ready to take your containerization game to the next level? If you read my previous article on containerization basics, you know that containerization allows developers to package and deploy applications seamlessly across different environments. However, managing containers at scale can quickly become a daunting task. That’s where Amazon Elastic Container Service (ECS) comes in. In this article, we’ll dive into the key features of ECS and share a client use case that highlights its potential. Plus, we’ll reveal some insider tips and tricks we’ve learned from our own ECS client projects. So buckle up and get ready to take your containerization to the next level with ECS.
Amazon ECS in General
First, let’s take a closer look at what makes ECS so powerful. ECS is a highly scalable, fully-managed container orchestration service provided by AWS. It makes it easy to run, stop, and manage Docker containers on a cluster. The service is a popular choice for those who are already using AWS and want a simple way to run and scale containerized applications.
Some of the key features of ECS include:
- Fully managed: ECS provides a managed container orchestration service, meaning that AWS manages the deployment and scaling of containerized applications.
- Highly scalable: The service can scale containerized applications automatically up or down in response to changes in demand, ensuring that the applications are always available and responsive.
- High availability: It offers high availability features, ensuring that applications are always available and responsive. This is achieved through features like deployments in multiple Availability Zones and automatic recovery of failed tasks.
- Flexible deployment strategies: AWS’s container service supports a range of deployment types, including rolling updates, blue-green-deployment with AWS CodeDeploy, and external deployments using third-party deployment controller.
- Serverless option: It provides a serverless option for running containerized applications using Fargate launch type. With Fargate, users can run containers without the need to manage underlying EC2 instances, making it a simple and cost-effective option for running containerized applications at scale.
- Hybrid/Multi-Cloud Option: The service also provides a hybrid/multi-cloud option with ECS Anywhere, allowing users to run and manage containerized applications on any infrastructure, including on-premises servers, virtual machines, and other cloud providers.
- Integration with other AWS services: ECS integrates seamlessly with other AWS services, such as Amazon Elastic Load Balancing (ELB) for automatically distributing traffic to their containerized applications, AWS CloudFormation to automate the deployment of ECS resources, or Amazon CloudWatch, making it easy to analyze and monitor containerized applications.
In ECS, a task is the fundamental unit of work that needs to be executed. A task is a set of one or more containers. While we’ll be simplifying things a bit by assuming only one container per task in this article, a more in-depth and technical blog article about ECS is already on the horizon.
ECS on EC2 vs. ECS on Fargate
When it comes to container orchestration on AWS, ECS on EC2 and ECS on Fargate are two of the most popular choices. Both options allow you to run and manage containerized applications, but which one is right for your needs? Let’s take a closer look at the differences.
With ECS on EC2, you are responsible for provisioning and managing the underlying EC2 instances that run your containers. This gives you more control over the infrastructure and the ability to customize it to your specific needs. With this type, you are charged for the EC2 instances running their containerized applications. ECS on EC2 is the right type for you if you have…
- Workloads requiring consistently high CPU core and memory usage
- Large workloads that need to be optimized for price (e.g. using reserved EC2 instances, or spot instances)
- Applications with the need to access persistent storage
ECS on Fargate is a serverless compute engine for containers that abstracts away the underlying infrastructure. This means that you don’t need to worry about provisioning or managing EC2 instances. Instead, Fargate automatically provisions the resources required to run your containers, based on the configuration and resource requirements you specify. You are charged per second for the resources used by your containerized applications, such as CPU and memory. Chose this type if you have…
- Large workloads that need to be optimized for low overhead
- Small workloads that have occasional burst (e.g. high traffic during the day, low traffic during the night)
- Tiny workloads (e.g. for test environments)
- Batch workloads (e.g. cron jobs, or occasional jobs)
ECS in Action: Client Use Case
Moving legacy software to the cloud can be challenging, but for one of our clients, a market-leading digital native business, the goal was clear: everything should be deployed to the cloud. With a lot of microservices and some monolithic applications in place, the company had to find the right tool to migrate all of their infrastructure.
ECS was the ideal solution for this client, as many of their services were already containerized. We provided support during the start of their migration journey, particularly for their Java Spring Boot web applications, which offered REST- or GraphQL APIs to other teams within the company. ECS easily handled these requirements, eliminating the need for API gateways to provide endpoints to other teams. To help the client’s other teams migrate to the cloud, we worked with them to develop a blueprint that ensured a smooth and successful transition.
Since the client wanted a serverless architecture to build upon, ECS on Fargate was chosen. ECS on EC2 would have been a more cost-effective option for the client, with the ability to use reserved instances due to the constant traffic on their systems. However, the architecture of their infrastructure, with a high number of services, made the maintenance extremely complex. Keeping all systems patched and updated would have required a whole team of developers, which would have negated any cost savings from AWS. Ultimately, with Fargate, the maintenance and management expenses were reduced, allowing the developers to focus on their core business operations.
To streamline the deployment process, we utilized Infrastructure as Code (IaC), ensuring that the process was efficient and repeatable. To achieve this, we recommended the use of AWS Cloud Development Kit (CDK) for deployment since it’s a great fit for ECS having several easy to use L2-constructs in place. With CDK, we were able to manage efficient and automated deployments of the client’s applications.
Further Insights on ECS
While working with multiple clients on ECS projects, we have gained several insights, especially while working with ECS on Fargate. One of the key observations we made was that while Fargate offers many benefits, its network performance can sometimes be slower than expected. We validated this by conducting a simple speedtest on Fargate, which confirmed our findings. Therefore, if there is a need for powerful network performance (e.g. to download big files), then ECS on EC2 may be a better option, as EC2 instances offer better network performance.
Another option that we found worth exploring was AWS Batch, which is a managed service that can provide an additional abstraction layer on top of Fargate. It allows you to run batch jobs of any scale, while ensuring that the underlying infrastructure is provisioned, managed, and scaled according to your needs.
ECS is a game-changing solution for managing containers on AWS, offering scalability and versatility to organizations looking to modernize their application infrastructure. As highlighted in the use case, ECS can play a crucial role in helping businesses migrate to the cloud and benefit from containerization. However, it is important to note that the choice between ECS on EC2 and ECS on Fargate depends on specific use cases and organizational requirements. Regardless of the choice made, ECS offers a reliable and flexible solution for managing containers on AWS and can help organizations stay ahead of the curve in today’s rapidly evolving technological landscape.
If you want to explore the differences between Containers, especially Kubernetes, and Function as a Service like AWS Lambda, check also our blog article in collaboration with blueshoe GmbH.