Mastering AWS Fargate CPU and Memory Combinations for Cost and Performance

Mastering AWS Fargate CPU and Memory Combinations for Cost and Performance

Introduction

Choosing the right Fargate CPU and memory combinations is more than just picking a random pair of values from AWS’s supported configurations. It directly affects your application’s performance, scalability, and cost efficiency. Many teams struggle with over-provisioning resources, which leads to unnecessary expenses, or under-provisioning, causing performance degradation. The key to getting this right is understanding your workload’s behavior, using the right monitoring tools, and optimizing based on actual usage.

However, there's a common misconception that Fargate Spot instances are too unreliable due to frequent reclaims. But with the right setup and region selection, you can take advantage of them while minimizing disruptions. Also, if you allocate less than 1 vCPU, performance issues may arise for web applications due to CPU throttling under load. This blog will dive into these nuances, showing you how to choose the best Fargate CPU memory combinations for your workloads.

Understanding Fargate CPU and Memory Combinations

AWS Fargate provides a predefined set of CPU and memory combinations. Unlike EC2-based ECS tasks, you cannot freely allocate CPU and memory in any ratio you want. Instead, AWS enforces specific pairing options to ensure efficiency across different workloads.

Here’s the Fargate CPU and memory combinations in a table format:

CPU ValueMemory ValueSupported Operating Systems
256 (.25 vCPU)512 MiB, 1 GB, 2 GBLinux
512 (.5 vCPU)1 GB, 2 GB, 3 GB, 4 GBLinux
1024 (1 vCPU)2 GB – 8 GBLinux, Windows
2048 (2 vCPU)4 GB – 16 GB (1 GB increments)Linux, Windows
4096 (4 vCPU)8 GB – 30 GB (1 GB increments)Linux, Windows
8192 (8 vCPU)16 GB – 60 GB (4 GB increments) (Fargate platform version linux 1.4.0+ required)Linux
16384 (16 vCPU)32 GB – 120 GB (8 GB increments) (Fargate platform version linux 1.4.0+ required)Linux

Possible AWS Fargate CPU memory combinations

For tasks hosted on Amazon EC2, supported CPU values range from 0.25 vCPUs to 192 vCPUs.

These constraints mean that when you scale your memory needs, your CPU allocation also needs to scale accordingly. This can lead to over-provisioning if you’re not careful.

Avoiding Performance Issues with Low vCPU Allocations

One major pitfall is allocating less than 1 vCPU for web applications. Many developers assume they can run web servers on 0.25 or 0.5 vCPU to save costs. While this may work for extremely lightweight applications, it often leads to performance degradation due to CPU throttling.

Why does this happen? AWS Fargate uses CPU shares to allocate time slices to each task. When multiple tasks run on the same host, lower vCPU allocations get fewer time slices, leading to unpredictable slowdowns under load. For a web application handling real-time requests, this can result in higher latencies and timeouts.

Solution:

For production web applications, always allocate at least 1 vCPU to ensure smooth request handling. If your workload is CPU-intensive, like video processing or machine learning inference, consider 2+ vCPUs for better performance.

Optimizing Costs with Fargate Spot Instances

Many teams avoid Fargate Spot instances due to the fear of their tasks being reclaimed frequently. However, with the right approach, you can leverage Spot instances without facing constant interruptions.

How to minimize task reclaims on Fargate Spot:

  1. Choose less competitive regions – AWS has varying Spot instance availability per region. Some regions have more excess capacity, meaning fewer reclaims.
  2. Use mixed-capacity deployments – Run critical workloads on On-Demand Fargate while using Spot instances for non-essential tasks.
  3. Deploy across multiple Availability Zones – This increases your chances of getting uninterrupted Spot capacity.
  4. Enable task retries – If a Spot instance is reclaimed, AWS ECS can automatically restart the task elsewhere.

By following these steps, many teams successfully run Fargate Spot tasks with weeks of uptime before encountering a reclaim. This can significantly reduce AWS costs—by up to 70% compared to On-Demand pricing.

Right-Sizing Based on Real Memory Utilization

One of the biggest cost optimizations for Fargate CPU memory combinations is right-sizing against memory usage. Many teams allocate too much memory, assuming their workloads need it, but in reality, memory utilization often remains low.

How to right-size your Fargate tasks:

  1. Use the Amazon CloudWatch agent to monitor memory and disk space utilization.
  2. Analyze memory usage over four weeks – If your max utilization is below 40%, you are over-provisioned.
  3. Adjust the memory allocation in your Fargate task definition based on real-world usage.

This strategy ensures you’re not paying for memory you don’t use while maintaining enough headroom to handle peak loads.

CloudWatch Agent Configuration Example

To enable memory monitoring, install the CloudWatch agent in your containers:

{
  "agent": {
    "metrics_collection_interval": 60,
    "region": "us-east-1"
  },
  "metrics": {
    "append_dimensions": {
      "ImageId": "${aws:ImageId}",
      "InstanceId": "${aws:InstanceId}",
      "InstanceType": "${aws:InstanceType}"
    },
    "metrics_collected": {
      "mem": {
        "measurement": ["mem_used_percent"],
        "metrics_collection_interval": 60
      }
    }
  }
}

This configuration tracks memory usage every 60 seconds, allowing you to analyze trends and make informed scaling decisions.

Avoiding “No Fargate Configuration Exists” Errors

When setting up Fargate tasks, it’s common to encounter the “No Fargate configuration exists for given values” error. This happens when you specify an unsupported CPU and memory combination in your ECS task definition.

To resolve this:

  • Double-check that your chosen CPU and memory values match one of AWS’s supported combinations.
  • Ensure your task definition is correctly formatted and doesn't include invalid memory or CPU values.

This issue is especially common in Terraform deployments, where incorrect values can lead to frustrating deployment failures.

If you attempt to register an invalid CPU setting, you may see the following error:

An error occurred (ClientException) when calling the RegisterTaskDefinition operation: Invalid 'cpu' setting for task.

Conclusion

Selecting the right Fargate CPU and memory combinations requires balancing cost, performance, and scalability. By ensuring that your CPU allocation isn’t too low, leveraging Spot instances wisely, and right-sizing memory based on actual usage, you can optimize your AWS costs while maintaining high performance.

For production workloads, always load test your applications before finalizing resource allocations. This ensures you’re not over-provisioning and paying for resources you don’t use. AWS provides the CloudWatch agent to help track real-world usage, making data-driven scaling decisions easier.

By following these best practices, you can run cost-efficient, high-performance workloads on AWS Fargate while avoiding common pitfalls.

Error: ClientException: No Fargate configuration exists for given values is the same error

Invalid 'cpu' setting for task or Invalid 'memory' setting for task are common error messages

Overwhelmed by AWS?

Struggling with infrastructure? We streamline your setup, strengthen security & optimize cloud costs so you can build great products.