Choosing one of the many services that Amazon Web Services offers, I want to start off with ECS as it’s the perfect segue from Microservices and Docker.
Containers
Containers allow developers to iterate at high velocity and offer the speed to scale to meet the demands of the application. It’s first important to understand what a container is, and how it enables teams to move faster.
-
Containers provide an isolation of processes.
-
Containers provide a standard way to package your application’s code, configurations, and dependencies into a single object.
-
Lightweight and portable: Containers share an operating system installed on the server and run as resource-isolated processes, ensuring quick, reliable, and consistent deployments, regardless of environment.
-
Run it reliable across different compute environments. Whether you deploy locally on your laptop or to production, the experience will remain the same (with the exception of secrets and other environmental values, of course!).
Containers are powerful way for developers to package and deploy their applications. They are lightweight and provide a consistent, portable software environment for applications to easily run and scale anywhere. Building and deploying microservices, running batch jobs, for machine learning applications, and moving existing applications into the cloud are just some of the popular use cases for containers. Some other benefits of containers include:
- Speed
- Workload Isolation
- Single artifact to test from local to production, avoid drift
Docker
- Docker is a software platform that allows you to build, test, and deploy applications quickly.
- Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime.
- Whether you are running on Linux, Windows, or macOS, you can run containers!
ECR
Amazon Elastic Container Registry transfers your container images over HTTPS and automatically encrypts your images at rest.
-
Integrated with ECS and Docker CLI.
-
Scalable and highly available.
-
100% cloud-based Docker container registry.
-
Many different services can be used to integrate ECR into a CI/CD Pipeline.
Container Orchestration
-
Running many containers at once is a difficult task.
-
Container Orchestration tools provide frameworks for managing, scaling and deploying containers.
-
Containers may not always live on the same physical infrastructure. It may need to be moved around or become part of a load balanced pool of resources.
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 deploy, run, manage and scale containerized applications on AWS. It deeply integrates with the rest of the AWS platform to provide a secure and easy-to-use solution for running container workloads in the cloud.
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. Amazon ECS leverages serverless technology from AWS Fargate to deliver autonomous container operations, which reduces the time spent on configuration, patching, and security.
-
Container-level networking
-
Advanced task placement
-
Deep integrations with AWS platform
-
ECS CLI
-
Scheduling Engines
-
Automatic Scaling
-
CloudWatch metrics
-
Load balancers
ECS itself is responsible for scheduling and orchestrating containers as well as allocating those containers on the underlying fleet of compute resources.
Cluster
An Amazon ECS cluster is a logical grouping of tasks or services.
- If you are running tasks or services that use the EC2 launch type, a cluster is also a grouping of container instances.
- If you are using capacity providers, a cluster is also a logical grouping of capacity providers.
- A Cluster can be a combination of Fargate and EC2 launch types.
When you first use Amazon ECS, a default cluster is created for you, but you can create multiple clusters in an account to keep your resources separate.
For more information on ECS Clusters, see here.
Task Definitions
To prepare your application to run on Amazon ECS, you create a task definition. The task definition is a text file, in JSON format, that describes one or more containers, up to a maximum of ten, that form your application.
It can be thought of as a blueprint for your application. Task definitions specify various parameters for your application. Examples of task definition parameters are which containers to use, which launch type to use, which ports should be opened for your application, and what data volumes should be used with the containers in the task. The specific parameters available for the task definition depend on which launch type you are using. For more information about creating task definitions, see Amazon ECS Task Definitions.
The following is an example of a task definition containing a single container that runs an NGINX web server using the Fargate launch type. For a more extended example demonstrating the use of multiple containers in a task definition, see Example Task Definitions.
{
"family": "webserver",
"containerDefinitions": [
{
"name": "web",
"image": "nginx",
"memory": "100",
"cpu": "99"
}
],
"requiresCompatibilities": [
"FARGATE"
],
"networkMode": "awsvpc",
"memory": "512",
"cpu": "256"
}
Tasks & Scheduling
A task is the instantiation of a task definition within a cluster. After you have created a task definition for your application within Amazon ECS, you can specify the number of tasks that will run on your cluster.
Each task that uses the Fargate launch type has its own isolation boundary and does not share the underlying kernel, CPU resources, memory resources, or elastic network interface with another task.
The Amazon ECS task scheduler is responsible for placing tasks within your cluster. There are several different scheduling options available. For example, you can define a service that runs and maintains a specified number of tasks simultaneously. For more information about the different scheduling options available, see Scheduling Amazon ECS Tasks.
Services
Amazon ECS allows you to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. This is called a service. If any of your tasks should fail or stop for any reason, the Amazon ECS service scheduler launches another instance of your task definition to replace it and maintain the desired count of tasks in the service depending on the scheduling strategy used.
In addition to maintaining the desired count of tasks in your service, you can optionally run your service behind a load balancer. The load balancer distributes traffic across the tasks that are associated with the service.
There are two service scheduler strategies available:
-
REPLICA:
- The replica scheduling strategy places and maintains the desired number of tasks across your cluster. By default, the service scheduler spreads tasks across Availability Zones. You can use task placement strategies and constraints to customize task placement decisions. For more information, see Replica.
-
DAEMON:
- The daemon scheduling strategy deploys exactly one task on each active container instance that meets all of the task placement constraints that you specify in your cluster. The service scheduler evaluates the task placement constraints for running tasks and will stop tasks that do not meet the placement constraints. When using this strategy, there is no need to specify a desired number of tasks, a task placement strategy, or use Service Auto Scaling policies. For more information, see Daemon.
Fargate
AWS Fargate is a technology for Amazon ECS that allows you to run containers without having to manage servers or clusters. It is a serverless compute engine for containers (it is a method to launch container services) that works with both Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS).With AWS Fargate, you no longer have to provision, configure, and scale clusters of virtual machines to run containers. This removes the need to choose server types, decide when to scale your clusters, or optimize cluster packing.
-
No infrastructure.
-
Manage everything at container level.
-
Resource-based pricing.
Unlike using EC2 instances in a ECS cluster, with Fargate, you are not responsible for managing a operating system, the ECS agent, various software and packages you have on the instance, patching and upgrading, and scaling the instance fleet for optimal utilization. Fargate handles all of this for you. AWS Fargate removes the need for you to interact with or think about servers or clusters. Fargate lets you focus on designing and building your applications instead of managing the infrastructure that runs them.
Service Discovery
Because containers are immutable by nature, they can churn regularly and be replaced with newer versions of the service. This means that there is a need to register the new and deregister the old/unhealthy services. To do this on your own is challenging, hence the need for service discovery.
AWS Cloud Map is a cloud resource discovery service. With Cloud Map, you can define custom names for your application resources, and it maintains the updated location of these dynamically changing resources. This increases your application availability because your web service always discovers the most up-to-date locations of its resources.
Cloud Map natively integrates with ECS. For more information on service discovery with ECS, see here.
Summary
-
Get Docker images on ECR.
-
Create ECS cluster. Can be Fargate or EC2.
-
Define Task and Service Definitions.
-
Launch running containers either on Fargate or EC2.
-
ECS scales and manages the containers.
References / Additional Information
#ContainersFromTheCouch - ECS Workshop Introduction - YouTube
AWS Basics for Beginners - Full Course - YouTube