Amazon ECS Lab3
Amazon ECS Lab3
https://www.scaler.com/topics/aws/aws-ecs/
Overview
AWS Elastic Container Service (ECS) is a fully managed container deployment service by
Amazon. It enables you to deploy your containerized applications easily without having to
configure an environment for the code to run it, with features like autoscaling and autorecovery.
ECS comes with two launch types: AWS EC2 and AWS Fargate.
Let's imagine you have just finished building an awesome application on your laptop and now
you deploy it globally so anyone can use your application. Maybe you can use AWS EC2
Instances to deploy your application? But then you will need to install the required libraries and
then deploy your code. Instead what if you could bundle your code into a package and let AWS
handle the deployment, along with automatic scaling and monitoring?
Amazon has designed AWS Elastic Container Service (ECS) for precisely this purpose. AWS
ECS provides a convenient container management service that is highly scalable and
automatable. It enables you to run images on the fly and fully utilize the benefits of
containerization.
Let's first understand the differences between an "image" versus a "container" and then jump into
the depths of AWS ECS.
Important Terminologies
Before delving into AWS ECS and its inner workings, we need to understand the following key
terminologies:
Container: A container "contains" all the required dependencies, libraries, and code to run an
application. Containers are like mini virtual machines which are independent of the underlying
hardware's operating system. This enables containers to be portable and scalable.
Image: If the container enables you to run applications, images enable you to "save" the
required dependencies, libraries, and code. Images are like snapshots of the mini virtual
machines and can be shared easily
Docker: Docker is one of the ways of running containers. Docker can be used to run an image as
a container on your laptop or in a production environment. This enables you to use the same
image across different environments without changing the application code.
Other than containers and images, which we learned about in the previous section, AWS ECS is
made up of various components:
Task Definitions: A task definition is a JSON file that contains the description of all the
containers that form your application. Configurations like which ports to open for your
application, which containers are dependent on each other, and what data volumes to use
can be mentioned in the task definition. A task definition can contain up to a maximum of
ten container descriptions.
Tasks: When you run a task definition in AWS ECS, a task is created. You can define
the number of tasks to run in a cluster, as well as if the task should be standalone or part
of a service.
Services: An AWS ECS service can be used to manage tasks in a cluster, and maintain a
defined number of running tasks. When you use a service to run a task, you do not need
to worry about failure recovery.
Clusters: An AWS ECS cluster represents a group of tasks or services. Your application
can use clusters to run independent tasks in isolation, which lets AWS ECS scale each
cluster separately as per demand.
Container Instance: A container instance is a single EC2 instance in the AWS ECS
cluster when you choose to use the "EC2 launch type".
Container Agent: A container agent is a service that runs on each container instance in
an AWS ECS cluster. The agent is responsible for sending data about the currently
running task and resource utilization.
AWS ECR: AWS Elastic Container Registry (ECR) is an online image repository where
users can store, share, and deploy container images. It is an important component of
AWS ECS as AWS ECS clusters pull images from AWS ECR to run tasks.
Explore free
Features of AWS ECS
AWS ECS comes with a whole host of features that makes deploying container-based
applications easy and efficient.
Strong Developer Support: AWS ECS has strong developer support in the form of Docker
compatibility and AWS Copilot. AWS ECS enables you to run and manage Docker containers
without any configuration changes. It also lets you use multiple images in one container with the
help of the Docker Compose tool. Amazon also provides its own tool, AWS Copilot, to easily
build, release and operate containerized applications. It automates the deployment process and
enables health monitoring of your services.
Intelligent Autoscaling and Autorecovery: AWS ECS has intelligent autoscaling and
autorecovery built-in. AWS ECS can scale the number of tasks as per the application's
demands and automatically recover unhealthy containers.
Task Scheduling: In AWS ECS, you can design tasks to run on a specific schedule and
shut down automatically after the processing has been completed. The task scheduling
feature of AWS ECS is both powerful and cost-effective.
Security and Isolation By Design: AWS ECS promotes security by design. It integrates
with AWS IAM and you can assign granular permissions for each of your containers.
You can run applications in clusters that are completely isolated from each other.
In-Built Monitoring and Logging: AWS ECS integrates with AWS
CloudWatch and AWS CloudTrail to enable monitoring and logging without any hassle.
You can monitor your container's resource utilization and analyze logs without leaving
the AWS Console.
Enabling Hybrid Deployments: Using AWS Outposts and AWS ECS together, you can
run containerized applications that depend on low latencies with on-premises
hardware. AWS Outposts is a fully managed service that brings AWS infrastructure to
your environment.
AWS ECS can be used in a variety of scenarios, a few of which are listed below:
In this launch type, you configure and deploy EC2 instances in your AWS ECS cluster to run
your containers.
Workloads that require consistently high CPU core and memory usage
Large workloads that need to be cost-effective
Applications that require access to persistent storage
When you need to directly manage your infrastructure for compliance or other reasons
Fargate Launch Type
In this launch type, containers run without any user management. AWS manages the
infrastructure and your containers run in a serverless pay-as-you-go environment.
There are many ways to deploy containers on AWS ECS. Let's take a look at the options:
Using the AWS Console: The quickest to get started with AWS ECS is by using the AWS Console.
Upload your image to AWS ECR and use the AWS ECS dashboard to create a task and run your
containers.
Using AWS Copilot: AWS Copilot provides a comprehensive way to build, test, and deploy
containers to AWS ECS. This is a CLI tool provided by AWS and is available on Windows, Mac OS,
and Linux-based OSes.
Using AWS CDK: If you want to programmatically control your AWS ECS deployment, the AWS
Cloud Development Kit (CDK) is an excellent choice. It provides helpful templates and tooling to
easily build task definitions and create clusters.
For detailed instructions, please refer to the official AWS Documentation, linked here.
AWS provides a few commands that can be run using the AWS CLI to interact with AWS ECS.
Here are a few key commands:
Using AWS ECS has a lot of benefits compared to other container-based deployment solutions:
Performance at Scale: AWS ECS enables your containerized applications to scale dynamically
and automatically, giving your application performance at scale with minimal configurations or
application code changes.
Integration with AWS Services: AWS ECS is tightly integrated with other AWS Services. Some
examples include AWS CloudWatch for monitoring, AWS CloudTrail for logging, AWS ALB for
load balancing, and AWS ECR as an image repository.
Cost Efficient: AWS ECS is a cost effective way of running your containerized applications. AWS
ECS automatically manages the hardware and further helps you save costs with features like
task scheduling for short-lived tasks and automatic recovery of unhealthy containers.
Improved Security: AWS ECS allows you to run applications in isolated containers and provide
granular permissions to containers, which enhances the security of your application as well as
your infrastructure.
In the case of either the AWS EC2 Launch Type or AWS Fargate Launch Type, you only pay for
the resources you use - there is no upfront cost for using AWS ECS.
For the AWS EC2 Launch Type: The pricing model is similar to paying for AWS EC2
Instances. You can choose from multiple ways to pay - from On Demand, Savings Plan,
Reserved Instances, or Spot Instances.
For the AWS Fargate Launch Type: The pricing models calculate costs based on the vCPU
and memory on an hourly basis. The hourly cost depends on the Operating System and CPU
Architecture chosen. You also have to pay additionally for any Storage costs.
For example, for a Linux x86 based system, the hourly costs are - $0.04048 per vCPU per hour
and $0.004445 per GB per hour (These rates are for us-west-2; the rates may vary per region).
Amazon Elastic Container Service (ECS) vs. Amazon Elastic Kubernetes Service (EKS)
Amazon Elastic Kubernetes Service (EKS) is another managed container deployment offering
by AWS which uses Kubernetes for orchestration. Here are the differences between AWS ECS
and AWS EKS:
You can provide granular permissions For permissions, AWS EKS requires additional
Security
using AWS IAM. plugins/configurations to use AWS IAM.
Pricing You only pay for the resources you use. You need to pay for both - the resources you use
and a separate charge for hosting the AWS EKS
AWS ECS AWS EKS
cluster.
Conclusion