AWS for the Real World

πŸ—οΈ Setting Up Your Containerized Applications with ECS

Published 5 months agoΒ β€’Β 5 min read

πŸ‘€ This is not properly displayed? Here is the online version! πŸ’‘

Hi Reader! πŸ‘‹

As you probably already know, we're an enormous fan of AWS Lambda. In our opinion, it's the fastest way of getting started with a new project; in most cases, you don't even need to worry about costs. Especially in the beginning.

However, container runtimes such as Amazon ECS are and will continue to be significant in numerous organizations. This is due to valid reasons.

If you're new to cloud computing, familiarizing yourself with ECS and Fargate is highly beneficial.

In this newsletter, we'll explore why and what you need to know to get started with this awesome service. πŸ—οΈ

Let's go! πŸ“š


Amazon ECS Infographic

If you can't wait to have all the important knowledge in a single place, have a look at our Amazon ECS infographic.


Evolution of Compute

In the traditional approach, application development and hosting were separate.

With cloud-native, they are integrated, allowing developers to leverage platform technologies that directly benefit their applications.

Public clouds like AWS, Azure, and GCP introduced containerization, where companies handed over infrastructure responsibility to cloud providers. Now, with services like Lambda, which are even more abstracted, developers can focus on features and business processes instead of operations.

Infrastructure can be created and destroyed quickly using code, enabling developers to replicate entire application ecosystems effortlessly. This means they can develop locally or remotely with a fully functioning duplicate of a production system, without impacting customers.


Amazon Elastic Container Service (ECS) is a highly scalable and efficient container management service. It provides a management platform for orchestrating containers in your cluster. With ECS, you can easily run, stop, and manage containers.

It is a battle-tested service that is well-suited for critical infrastructure handling high-volume microservice API requests.

ECS offers several features that simplify the development process, reduce operational tasks, and minimize liabilities.

  • πŸ€– With the Fargate launch type, you don’t need to worry about the underlying infrastructure. Simply choose the container image you want to run and specify the required memory and virtual CPUs.
  • πŸ” ECS seamlessly integrates with AWS IAM, allowing you to define precise permissions based on your needs. You can easily manage access without dealing with usernames and passwords, and enforce compliance requirements.
  • πŸ•΅οΈβ€β™€οΈ ECS integrates with CloudWatch, providing metrics and log messages for monitoring and troubleshooting.

As we believe in the future of cloud-native applications, we will focus on the basics of the Fargate Launch Type and not delve into the details of the EC2 Taunch Type.

Key Concepts of ECS

While exploring and learning about ECS, you'll come across many important terms that may not be immediately clear or easy to understand. This is completely normal, and we've felt this as well.

Being honest here: In the initial months of working with ECS, despite having apps in production, we encountered challenges in differentiating between the terms tasks, task definitions, clusters, and services.

However, they are essential for comprehending how all the different components of ECS interact. Let's delve into it!

  • πŸ—οΈ Container: Docker is a core building block of container services, allowing you to create lightweight environments for running applications across different operating systems, while ECS simplifies the management and orchestration of containers, enabling developers to focus on application development.
  • πŸ“ Task Definition: A task definition is a blueprint for launching one or several containers. Task definitions are defined using the Docker-Compose file format, allowing you to specify container images, environment variables, port mappings, and other configurations for each container within the task.
  • πŸ€– Task: A task is the execution of a task definition, consisting of multiple containers running together on a single host.
  • πŸ‘Ύ Service: A service is a persistent process that oversees a collection of tasks and ensures that a specified number of tasks are always active. If a task terminates unexpectedly, such as when a container exits due to runtime errors, and the number of functioning tasks drops below a predefined threshold, ECS will automatically initiate a new task as a replacement.
  • πŸ“ Cluster: A cluster is a logical grouping of tasks or services. These tasks and services are executed on infrastructure that is associated with a cluster. The infrastructure can be provided by AWS Fargate, EC2 instances managed by yourself, on-premise servers, or remotely managed virtual machines.

Fargate: A Serverless Compute Option

Fargate is a serverless, pay-as-you-go option where you don't have to worry about maintaining any infrastructure. With Fargate, all you need to do is specify the task definition, cluster, and desired number of tasks, and ECS takes care of everything else.

Fargate automatically provisions the necessary compute resources, like Amazon EC2 instances (which are completely abstracted and therefore not your responsibility), and runs the tasks on those instances.

It's the recommended launch type for workloads of any size that may require low overhead and occasional bursts. If you're unsure about your requirements, always choose the Fargate launch type to minimize operations and responsibilities.

The Lifecycle States of a Task

A task goes through various lifecycle stages, regardless of whether it was initiated manually or as part of a service.

The ECS container agent by Amazon monitors all state changes, keeps track of the last known state, and maintains the desired state.

ECR to Store Your Images

ECS with Fargate relies exclusively on container images. You can store these images in the Amazon Elastic Container Registry (ECR), a fully managed container registry that allows you to host and share an unlimited number of images and artifacts.

ECR seamlessly integrates with ECS, as well as Amazon Elastic Kubernetes Service (EKS) and AWS Lambda.

There are no upfront costs associated with ECR. You only pay for the data storage and transfer costs to the internet. This means that when Fargate pulls images to run your containerized tasks, there are no additional charges incurred.

Auto Scaling

ECS provides a range of options for scaling the number of tasks in a cluster, allowing you to effectively manage workload and optimize resource utilization:

  • Step Scaling Policies: This policy type sets thresholds for CPU or memory usage in ECS. For example, you can add a new task if CPU usage exceeds 70% for 2 minutes, up to 10 tasks. You can also stop a task if CPU utilization falls below 40% for 2 minutes. Set cool-down periods to control task starts or stops, and define a deployment phase to prevent auto-scaling from CPU spikes during container startup.
  • Target Tracking Scaling Policies: With target tracking, ECS Service Auto Scaling creates and manages CloudWatch alarms for scaling actions. Set a target utilization level, like an average CPU utilization of 75%, and ECS will add or remove tasks to maintain the metric close to the target value. This allows dynamic scaling for varying workloads and optimized resource allocation.
  • Scheduled Scaling Policies: For predictable load patterns, use scheduled scaling policies. This adjusts the number of tasks and containers in your cluster based on known load patterns. ECS automatically adjusts the desired number of tasks based on specified date and time, ensuring the cluster is right-sized for expected traffic during different periods.

Deploying your First Application with ECS

If you are interested in learning how to deploy your first application on ECS, we have a detailed step-by-step guide in our β€‹πŸ“™ AWS Fundamentals e-book​ that provides instructions on how to deploy a Node.js app on ECS with Fargate!


That's it for today folks! πŸŽ‰

We hope you have a great week & hear you soon! πŸ‘‹

Sandro & Tobi

Still hungry for AWS content? Have a look at our blog! πŸ“š ↓

AWS for the Real World

by Tobi & Sandro

Join our community of over 8,800 readers delving into AWS. We highlight real-world best practices through easy-to-understand visualizations and one-pagers. Expect a fresh newsletter edition every two weeks.

Read more from AWS for the Real World

Hi Reader πŸ‘‹πŸ½ This week, we're diving headfirst into the deep end of AWS's pool of innovations with the IAC Generator β€” a tool that's been causing quite the buzz. The promise AWS gives us is quite bold: Generate AWS CloudFormation templates and AWS CDK apps for existing AWS resources in minutes. But does it really work? Let's find out together. This will be a hands-on πŸ‘·πŸ½β€β™€οΈ issue. For the impatient, TL;DR, in a nutshell, πŸ₯œ: Good for a start, but far away from usable in production. The...

6 days agoΒ β€’Β 5 min read

This is not properly displayed? Read all of our issues online! πŸ’‘ Hi Reader πŸ‘‹πŸ½ We've said it more than once and we still stand with it: AWS IAM is the most complete but still underlooked service out there. Overwhelmingly, engineers look at the way of least resistance via "Which permissions do I have to grant to make this work? πŸ€”" or directly using wildcards for actions and resources on all policies, instead of diving into all the aspects of the service and its possibilities. Nevertheless, it's...

21 days agoΒ β€’Β 4 min read

Hey Reader, amazing that you're interested in creating the CloudWatch Book together with us. This is the third CloudWatch Update. Coincidentally, Sandro (I'm writing this update) turned 30 last week πŸ₯³ In this update, we'll introduce you to our newly created web application: The GitHub Repository Tracker. While it is not the fanciest name it, the project will help you a lot in learning & understanding CloudWatch for the real world. We thought it would be much easier to show it in a video so...

29 days agoΒ β€’Β 6 min read
Share this post