1. Introduction
The introduction provides an overview of the article's focus, which is to present a comprehensive guide on AWS Elastic Container Service (ECS) Fargate and Elastic Container Registry (ECR). It may briefly explain the significance of ECS Fargate for running containers without managing servers and ECR as a container image registry.
2. Purpose
This section states the purpose of the article, which is to educate readers about AWS ECS Fargate and ECR and demonstrate how to set them up using the AWS Management Console and Prismscaler. It aims to provide both DevOps and non-DevOps methods to cater to different experience levels.
3. What is AWS ECS Fargate Launch type?
AWS ECS (Elastic Container Service) Fargate is a compute engine for Amazon Elastic Container Service. It's a technology that allows you to run containers without having to manage the underlying infrastructure. Here's a breakdown of what AWS ECS Fargate is and how it works:
- Container Orchestration: AWS ECS is a fully managed container orchestration service that helps you deploy, manage, and scale containerized applications using Docker containers. It's similar to other container orchestration platforms like Kubernetes, but it's designed to work seamlessly within the AWS ecosystem.
- Serverless Compute: ECS Fargate takes the serverless approach to container management. With traditional ECS, you have to provision and manage EC2 instances to run your containers. In contrast, ECS Fargate abstracts away the underlying EC2 instances. You just define your containerized application and its resource requirements (CPU and memory), and AWS takes care of launching and managing the underlying infrastructure.
- Benefits:
- Simplicity: Fargate simplifies the container management process by eliminating the need to manage EC2 instances. You can focus solely on defining and running your containers.
- Resource Isolation: Each Fargate task (an instantiation of a container) runs in its own isolated environment, which enhances security and resource isolation.
- Scalability: Fargate allows you to easily scale your containers up or down based on application demand without worrying about the underlying infrastructure.
- Use Cases:
- Microservices: ECS Fargate is well-suited for microservices architectures, where each microservice can run in its own container with its own resource allocation.
- Batch Processing: It's useful for running batch jobs and other workloads that require isolated compute environments.
- Continuous Integration/Continuous Deployment (CI/CD): Fargate can be integrated into CI/CD pipelines to deploy containerized applications rapidly.
- Pricing: AWS ECS Fargate pricing is based on the vCPU (virtual CPU) and memory resources allocated to your tasks. You only pay for the resources you use when your containers are running.
4. What is ECR?
Amazon Elastic Container Registry (ECR) is a fully managed Docker container registry service provided by Amazon Web Services (AWS). It allows you to store, manage, and deploy Docker container images, making it easier to work with containers in the AWS cloud environment. Here are some key features and aspects of Amazon ECR:
- Private Docker Registry: ECR is a private registry, which means you can store your Docker images securely without exposing them to the public internet. This is important for maintaining the security of your containerized applications.
- Integration with AWS Services: ECR is tightly integrated with other AWS services, particularly Amazon ECS (Elastic Container Service) and Amazon EKS (Elastic Kubernetes Service). This integration simplifies the process of deploying containers on AWS and ensures seamless compatibility.
- High Availability and Scalability: ECR is designed for high availability and scalability. Your container images are replicated across multiple Availability Zones within an AWS Region to ensure redundancy and fault tolerance. This ensures that your images are available even in the event of a failure in one Availability Zone.
- Fine-Grained Access Control: You can control access to your container images using AWS Identity and Access Management (IAM) policies. This allows you to restrict who can push, pull, or manage your container images in the registry.
- Lifecycle Policies: ECR supports lifecycle policies, which automatically clean up old or unused images. This helps you manage storage costs and keeps your registry organized.
- Docker CLI Integration: You can use the Docker CLI to interact with ECR, making it easy to push and pull images from ECR repositories using familiar Docker commands.
- Scan for Vulnerabilities: ECR provides integration with Amazon ECR Image Scanning, which can automatically scan your container images for software vulnerabilities. This helps you identify and address security issues before deploying containers.
- Cross-Region Replication: You can replicate your container images to different AWS regions, allowing you to deploy containers closer to your end-users or comply with data residency requirements.
- Integration with CI/CD Pipelines: ECR is commonly used in continuous integration and continuous deployment (CI/CD) pipelines. You can store your container images in ECR and then use them in your CI/CD workflow to deploy applications to ECS, EKS, or other container platforms.
- Cost Structure: ECR pricing is based on the amount of data stored in the registry and data transferred out to other AWS regions. It's important to consider the cost implications when using ECR in your container deployment strategy.
5. Creating AWS ECS Fargate launch type with AWS console
Step 1. Create Load balancer
1.1. Create target group
Each target group is used to route requests to one or more registered targets. When a rule condition is met, traffic is forwarded to the corresponding target group.
Go to Load balancer feature in EC2 service → go to Target group → click to Create target group:
For Choose a target type,Instances to register targets by instance ID, IP addresses to register targets by IP address, or Lambda function to register a Lambda function as a target.
If your service's task definition uses the awsvpc network mode (which is required for the Fargate launch type), you must choose IP addresses as the target type This is because tasks that use the awsvpc network mode are associated with an elastic network interface, not an Amazon EC2 instance.
In this context, we choose IP addresses type.
You can skip the target selection, we will update later. Then, create target group.
1.2. Create load balancer
Navigate to Load Balancers → click to Create load balancer:
In this blog, we use Application Load Balancer, please choose it:
Configure basic configuration:
- For Scheme, choose Internet-facing or Internal. An internet-facing load balancer routes requests from clients to targets over the internet. An internal load balancer routes requests to targets using private IP addresses.
- For IP address type, choose the IP adressing for the containers subnets. In Network mapping, choose the VPC and the subnets for your load balancer.
- For VPC, select the same VPC that you used for the container instances on which you intend to run your service.
- For Mappings, select the Availability Zones to use for your load balancer. If there is one subnet for that Availability Zone, it is selected. If there is more than one subnet for that Availability Zone, select one of the subnets. You can select only one subnet per Availability Zone. Your load balancer subnet configuration must include all Availability Zones that your container instances reside in.
- For Name, enter a name for the container.
- For Image URI, enter the image to use to start a container. Images in the Amazon ECR Public Gallery registry may be specified using the Amazon ECR Public registry name only. For example, if public.ecr.aws/ecs/amazon-ecs-agent:latest is specified, the Amazon Linux container hosted on Amazon ECR Public Gallery is used. For all other repositories, specify the repository using either the repository-url/image:tag or repository-url/image@digest formats.
- A port mapping allows the container to access ports on the host to send or receive traffic. Under Port mappings, do one of the following:
- When you use the awsvpc network mode, for Container port and Protocol, choose the port mapping to use for the container.
- When you use the bridge network mode, for Container port and Protocol, choose the port mapping to use for the container.
6. Creating AWS ECS Fargate launch type with Prismscaler
Prism Scaler provides you with an intuitive model and a concise form, you just need to fill in the necessary information and press create, now PrismScaler will automatically build a simple web application/system that moves on a container on AWS:
On AWS, PrismScaler will help you create these resources:
・ ECR (early NGINX image)
・ Application load balancer, Target group
・ ECS (Cluster, Service, Task)
・ Role related Role, SecurityGroup
Estimated Time
5-15 minutes (without DevOps knowledge)
7. Reference
The reference section lists the sources or external materials used in the article, allowing readers to explore further or verify the information provided.