AWS Fargate
Overview
- In this modern era, companies are shifting their computer applications/software from traditional monolithic to microservices architecture
- Thanks to Docker, Containers made the success of microservices architecture easy.
What is Container ?
- Containers let us package our code so we can run our code anywhere.
- Before Container technology, we had to provision and manage servers often requiring complex infrastructure to run our containers
- With AWS Fargate, we can now run serverless containers as we don't have to manage any servers
What is AWS Fargate and Why Do You Need It?
AWS Fargate is the serverless container service/technology provided by AWS. It is also compatible with both the Elastic Container Service and Elastic Kubernetes services. Fargate can quickly launch tens of thousands of container instances/tasks and will seamlessly scale to meet our application compute requirements.
Components
- Cluster
- Task Definition
- Task
- Service
- Repositories
Clusters
- Clusters contain services that run Tasks or servers.
- The task is considered a Serverless Container Provisioned by AWS Fargate whereas the Server meant the Ec2 instance provisioned by us.
- Clusters are often considered logical entities for the collection of tasks or servers in a service.
Task definitions
- Task definition is used as a blueprint to run our application in fargate tasks.
- Task definition primarily includes the Docker image of our application.
- It also includes how much VCpu (virtual CPU )and memory (RAM) should use for each task or container along with many other attributes.
Reference:Task Definition Parameters
Tasks
The task is the containers server launched by AWS Fargate based on the task definition we defined
Services
- Services help us to maintain and run the desired /specified number of container tasks or servers as per our needs in a cluster.
- Load balancer can be used in services to distribute the traffic among the task within the services.
- ECS Services is using a rollback deployment strategy for every task definition revision updated in services by default.
For Example:
Assume, we are having an ECS service named service-1 which is having task definition named task-def-1:1. Service is running with 1 task If the developer/Devops engineer made the task revision from task-def-1:1 to task-def-1:2 and apply the changes in services ECS service will launch the new task. Once the new task will become healthy, then only, the existing or old task will replace and terminate. If the new task failed to launch, the old task will be running state until the new task becomes healthy. Thus we can achieve zero downtime for our deployment.
We can also choose Blue/Green deployment with CodeDeploy or External deployment while creating services.
Repositories
- Repositories contain docker image URLs that will be used in task definition to deploy the application.
- Repositories can be public or private.
Operating System and CPU Architecture
There are two architectures and 3 Operating systems supported by AWS fargate to containerize our application.
OS/ Arc | x_86_64 | ARM |
---|---|---|
Amazon Linux 2 | Supported | Supported |
Windows Server 2019 Core | Supported | Not supported |
Windows Server 2019 Full | Supported | Not supported |
- We don’t need to buy any license from Microsoft for using windows containers. The license fee will include in the bill.
- AWS will take care of OS License Management.
Working of AWS Fargate
AWS Fargate working components can be majorly classified as below mentioned three components
- Front-end service
- Cluster Manger-sub system
- Capacity Manager-sub system
Front-end service
- This is the entry point (public endpoints) for aws fargate.
- The service is responsible for performing IAM authentication/authorization and limit enforcement.
Cluster Manager-Sub system
This is the backend service of aws fargate working under the hood which keeps track of clusters and tasks which are running within the cluster
Capacity Manager-Sub system
- This service is responsible for picking available instances which are in the warm pool and available instances that are ready to launch.
- This service is also responsible for picking the correct instance type and size based on the task definition defined in the services.
- It controls the replenishing of instance/ task.
Sample workflow under the hood of aws fargate
Windows containers on AWS Fargate Considerations
- We won’t be able login into the windows container server as aws fargate does not support direct access to RDP or RPE to the underlying OS.
- However, using ALB in the ECS services as Front-end, we can expose our windows container task in the target group as a backend to ALB.
- We will be able to access the windows server via the ALB DNS URL.
- Using the AWS logs driver in the windows container, we will be able to send log stream information to CloudWatch Logs.
Note: While creating task definition, we have to configure aws logs under the storage and logging section
AWS Fargate Demo ( Deploy a Simple Web Application on Amazon ECS using AWS Fargate Launch Type)
Remember the below workflow once you created the cluster in aws ECS for fargate.
Repositories–>Task definition–>Services
For custom images or private images Create an ECS cluster with fargate as compute options Step 1: Create a repositories Step 2: Create a task definition Step 3: Create a services
For this demo , we are using public docker image only so, we don't need to create repositories.
Cluster
- Login to aws console and choose ECS or Elastic container service.
- In the left navigation pane, click cluster and click create cluster.
- Enter the desired cluster name and choose the vpc and subnets.
Note: For this demo to work, you should use public subnets
- Review the Cluster type and VPC and subnet details and create it
Note: Once you created a cluster, you won't able to change the launch type and network configuration, those settings are immutable.
Task Defintion
Create task definition with the below parameters
- Name : Give any desired name
- Image url : httpd:2.4
- Vcpu : 0.25Vcpu
- Memory : 0.5GB
- Role : ecsTaskExecutionRole
- Enter the name as convention mentioned in the console
- Enter the image url as http:2.4 as mentioned in the below image
- Choose port 80 if it is not automatically selected
- Choose default ecsTaskExecutionRole
- Choose 0.25Vcpu and 0.5 GB Memory for our container task
- Choose default for the remaining options and create a task definition
Service
- Click Cluster and create service
- Choose the task defintion we created with the latest revision (1).
- Enter Desired number of task = 1
- Enter Minimum number of task = 1
- Enter Maximum number of task = 1
- Enable Auto-assign public IP
- Let the remaining options be default
- Review and Deploy it.
Task
- Go to the service and click task.
- Copy the public IP of the task and paste it in browser url.
- You will see the below image.
Troubleshooting
If you are not able to get the expected response from the url as mentioned above image.
- Make sure Assign public IP is Enabled
- Check whether you are using public subnets or not .
- Check the security group Inbound rule.
The rule should look like below
4.Check the taskrole in task defintion and servicelinkedrole in service
- Task role Name : ecsTaskExecutionRole
- Service role Name: AWSServiceRoleForECS
If you need further help for troubleshooting, Kindly refer below documentation
Pricing
Pricing will based on the below-mentioned 5 independent dimensions we configured in our aws fargate services.
They are Vcpu, Memory, Storage, Operating system and Cpu Architecture.
Dimensions | Linux X86_64 | Linux ARM | Windows X86_64 |
---|---|---|---|
per vcpu per hour | $0.04256 | $0.03405 | $0.09619 |
per GB per hour | $0.004655 | $0.00372 | $0.01052 |
OS license Fee | - | - | $0.046 |
per storage GB per hour | $0.000127 | $0.000127 | $0.000127 |
By Default, 20GB of Ephermal storage will be provided by Fargate task and pods.
Bills are charged only for additional storage we configure.
Note: The above mentioned pricing is based on Mumbai region
For more details for pricing on specific regions. Kindly refer below
Conclusion
- AWS Fargate is a serverless container solution with seamless scaling capabilities.
- Using AWS Fargate, Customers can build an application without worrying about managing the servers and OS Patching, scaling, deployment, etc.
- One can consider as AWS Fargate the best option if their application includes mutiple microservices.