Table of Contents¶
-
What is AWS Fargate?
-
Benefits of AWS Fargate
-
Fargate vs EC2 launch types
-
Key Concepts
-
Prerequisites
-
Using AWS Fargate with ECS
-
a. Create a Fargate Cluster
-
b. Define Task Definition for Fargate
-
c. Create and Run a Service
-
d. Access Your Application
-
-
Using AWS Fargate with EKS
-
a. Enable Fargate Profile
-
b. Deploy Workloads on Fargate
-
-
Monitoring and Logging
-
Pricing Model
-
Best Practices
-
Cleanup
-
Troubleshooting
1. What is AWS Fargate?¶
AWS Fargate is a serverless compute engine for containers that works with Amazon ECS and EKS. It lets you run containers without provisioning or managing servers or clusters. You just define your application and Fargate manages the infrastructure.
2. Benefits of AWS Fargate¶
-
No server management — no need to manage EC2 instances
-
Right-size your resources — pay per running container resource
-
Seamless scaling — automatically scales your containers
-
Improved security — isolation at the task level
-
Integration with AWS services — IAM roles, CloudWatch, VPC, etc.
3. Fargate vs EC2 Launch Types¶
| Feature | Fargate | EC2 Launch Type |
|---|---|---|
| Server management | None (fully managed) | User manages EC2 instances |
| Pricing | Pay per container per second | Pay for EC2 instances |
| Scaling | Automatic | User-managed |
| Use case | Simple, serverless, microservices | Custom AMIs, more control |
4. Key Concepts¶
-
Task — A running container or set of containers (defined in Task Definition)
-
Task Definition — Blueprint for your task, including image, CPU, memory, networking, IAM roles
-
Cluster — Logical grouping of tasks or services
-
Service — Long-running task that you want to keep running
-
Fargate Profile (for EKS) — Defines which pods run on Fargate
5. Prerequisites¶
-
AWS CLI installed and configured
-
AWS account with permissions to ECS, EKS, IAM
-
Docker (optional for local image build)
6. Using AWS Fargate with ECS¶
a. Create a Fargate Cluster¶
b. Define a Task Definition¶
Example task definition (fargate-task.json):
{
"family": "fargate-task",
"networkMode": "awsvpc",
"executionRoleArn": "arn:aws:iam::YOUR_ACCOUNT_ID:role/ecsTaskExecutionRole",
"containerDefinitions": [
{
"name": "nginx",
"image": "nginx",
"portMappings": [
{
"containerPort": 80,
"protocol": "tcp"
}
],
"essential": true
}
],
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "256",
"memory": "512"
}
Register the task definition:
c. Create and Run a Service¶
aws ecs create-service \
--cluster my-fargate-cluster \
--service-name my-fargate-service \
--task-definition fargate-task \
--desired-count 1 \
--launch-type FARGATE \
--network-configuration "awsvpcConfiguration={subnets=[subnet-xxxxxx],securityGroups=[sg-xxxxxx],assignPublicIp=ENABLED}"
d. Access Your Application¶
Get the public IP of the task by describing it or via the assigned ELB if configured, then access it on port 80.
7. Using AWS Fargate with EKS¶
a. Enable Fargate Profile¶
Create a Fargate profile specifying which pods run on Fargate:
eksctl create fargateprofile \
--cluster my-cluster \
--name my-fargate-profile \
--namespace default
b. Deploy Workloads on Fargate¶
Any pod in the default namespace will run on Fargate.
Example pod manifest (nginx-fargate.yaml):
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: default
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Deploy:
8. Monitoring and Logging¶
-
Use CloudWatch Logs for container logs
-
Use AWS X-Ray for tracing
-
Use AWS CloudWatch Container Insights for cluster metrics
9. Pricing Model¶
-
Charged per CPU and memory used by running tasks per second
-
No charge for EC2 instances since you don’t manage servers
10. Best Practices¶
-
Use IAM Roles for Tasks for least privilege access
-
Assign correct subnet and security groups for networking
-
Monitor resource utilization and scale accordingly
-
Use auto scaling with ECS services
11. Cleanup¶
aws ecs delete-service --cluster my-fargate-cluster --service my-fargate-service
aws ecs delete-cluster --cluster my-fargate-cluster
12. Troubleshooting¶
-
Tasks stuck in
PENDING— check subnet and security group setup -
Service does not receive traffic — verify Load Balancer and target group
-
Logs missing — ensure CloudWatch logging is enabled and IAM roles are correct
Sure! Here’s a solid list of AWS Fargate interview questions categorized by difficulty, along with brief answers to help you prepare:
AWS Fargate Interview Questions & Answers¶
Basic¶
-
What is AWS Fargate?
AWS Fargate is a serverless compute engine for containers that allows running containers without managing the underlying EC2 instances. -
How does Fargate differ from the EC2 launch type in ECS?
Fargate removes the need to manage servers; EC2 launch requires provisioning and managing instances. -
Which AWS services support Fargate?
Amazon ECS and Amazon EKS support running containers on Fargate. -
What are the key components of a Fargate task?
Task Definition, Cluster, Service, and Task. -
What is the pricing model for AWS Fargate?
Pay-per-use based on vCPU and memory resources consumed by running tasks.
Intermediate¶
-
What networking modes does Fargate support?
awsvpcmode is used in Fargate, giving each task its own elastic network interface (ENI). -
How do you assign permissions to a Fargate task?
Using IAM Roles for Tasks (task execution role and task role). -
Can you explain the difference between task execution role and task role in Fargate?
Execution role is used by ECS agent to pull images and write logs; task role is assumed by containers to access AWS services. -
What are some best practices when using Fargate?
Use least privilege IAM roles, monitor resource usage, use private subnets for security, and configure logging properly. -
How do you enable logging for containers running on Fargate?
Configure theawslogslog driver in the task definition to send logs to CloudWatch Logs.
Advanced¶
-
How does Fargate handle scaling?
You can configure ECS service Auto Scaling to add or remove tasks based on CloudWatch alarms. -
What limitations should you be aware of when using Fargate?
Certain resource limits per task (e.g., max CPU and memory), lack of support for privileged containers, no support for custom AMIs. -
How can you troubleshoot a Fargate task stuck in
PENDINGstate?
Check subnet availability, ENI limits, security groups, IAM permissions, and whether your VPC has sufficient IP addresses. -
Explain how Fargate integrates with AWS VPC.
Each Fargate task gets an elastic network interface in the specified VPC subnets, allowing fine-grained network control. -
What is the difference between AWS Fargate and Lambda?
Fargate runs containers and is suitable for long-running or stateful services; Lambda is for short-lived serverless functions.
Scenario / Practical¶
-
How would you migrate an ECS cluster from EC2 launch type to Fargate?
Update task definitions to useFARGATEcompatibility, configure network mode toawsvpc, create a new Fargate service, and migrate traffic gradually. -
How do you secure sensitive information (like DB credentials) in Fargate tasks?
Use AWS Secrets Manager or AWS Systems Manager Parameter Store, and inject secrets as environment variables or files. -
Describe how you would deploy a multi-container application on Fargate.
Define multiple containers in a single task definition with proper resource allocation and networking. -
What happens if your Fargate task uses more memory than allocated?
The task will be terminated by ECS due to out-of-memory (OOM) errors. -
Can you run GPU workloads on Fargate?
No, Fargate currently does not support GPU-enabled tasks.