Skip to content

Table of Contents

  1. What is AWS Fargate?

  2. Benefits of AWS Fargate

  3. Fargate vs EC2 launch types

  4. Key Concepts

  5. Prerequisites

  6. 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

  7. Using AWS Fargate with EKS

    • a. Enable Fargate Profile

    • b. Deploy Workloads on Fargate

  8. Monitoring and Logging

  9. Pricing Model

  10. Best Practices

  11. Cleanup

  12. 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

aws ecs create-cluster --cluster-name my-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:

aws ecs register-task-definition --cli-input-json file://fargate-task.json

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:

kubectl apply -f nginx-fargate.yaml

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

  1. What is AWS Fargate?
    AWS Fargate is a serverless compute engine for containers that allows running containers without managing the underlying EC2 instances.

  2. 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.

  3. Which AWS services support Fargate?
    Amazon ECS and Amazon EKS support running containers on Fargate.

  4. What are the key components of a Fargate task?
    Task Definition, Cluster, Service, and Task.

  5. What is the pricing model for AWS Fargate?
    Pay-per-use based on vCPU and memory resources consumed by running tasks.


Intermediate

  1. What networking modes does Fargate support?
    awsvpc mode is used in Fargate, giving each task its own elastic network interface (ENI).

  2. How do you assign permissions to a Fargate task?
    Using IAM Roles for Tasks (task execution role and task role).

  3. 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.

  4. 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.

  5. How do you enable logging for containers running on Fargate?
    Configure the awslogs log driver in the task definition to send logs to CloudWatch Logs.


Advanced

  1. How does Fargate handle scaling?
    You can configure ECS service Auto Scaling to add or remove tasks based on CloudWatch alarms.

  2. 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.

  3. How can you troubleshoot a Fargate task stuck in PENDING state?
    Check subnet availability, ENI limits, security groups, IAM permissions, and whether your VPC has sufficient IP addresses.

  4. 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.

  5. 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

  1. How would you migrate an ECS cluster from EC2 launch type to Fargate?
    Update task definitions to use FARGATE compatibility, configure network mode to awsvpc, create a new Fargate service, and migrate traffic gradually.

  2. 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.

  3. 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.

  4. 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.

  5. Can you run GPU workloads on Fargate?
    No, Fargate currently does not support GPU-enabled tasks.