AWS Cloud Financial Management

AWS Compute Optimizer launches support for Amazon ECS services on AWS Fargate

Optimizing compute resources is one of the most important customer concerns as they look to maximize the return on investment of their AWS spend. Over-provisioning compute can lead to unnecessary infrastructure costs, while under-provisioning can lead to poor application performance. In December 2019, we launched AWS Compute Optimizer to help customers identify optimal Amazon Elastic Compute Cloud (Amazon EC2) instance types for their applications. Over time, we have expanded Compute Optimizer support to more resource types, such as Amazon Elastic Block Store (Amazon EBS) volumes, and AWS Lambda functions.

With containers gaining popularity in software engineering, one of the most common customer requests we receive is related to supporting containerized applications. Today, we are expanding Compute Optimizer recommendations to help you identify optimal CPU and memory configurations for Amazon Elastic Container Service (Amazon ECS) services running on AWS Fargate.

Many customers run hundreds of applications with Amazon ECS on Fargate each day. To keep their infrastructure optimized, customers normally assign dedicated engineers in each service team to analyze their Fargate CPU and memory usage and make adjustments regularly. This effort and cost add up over time as applications and usage patterns change and new applications are deployed, and it is difficult to keep up with this task.

With these new recommendations, you no longer need to dedicate engineering resources to analyze CPU and memory utilization for your Amazon ECS services on Fargate. Compute Optimizer continuously monitors your ECS services, using historical resource utilization metrics to generate recommendations. You can easily realize cost savings and performance improvement potentials by implementing AWS Compute Optimizer’s recommendations.

Let’s get started by walking through how to enable Compute Optimizer, and understand and apply its recommendations for Amazon ECS services on Fargate.

Enabling Compute Optimizer

In your AWS account, opt in to Compute Optimizer to start analyzing your AWS resources. Ensure you have the appropriate IAM permissions configured by following these steps. If you prefer to use the console to opt in, follow these steps. To opt in via CLI, enter the following command in a terminal window:

$ aws compute-optimizer update-enrollment-status --status Active

Understanding the Compute Optimizer recommendations

Once you enable Compute Optimizer, it starts generating Amazon ECS services on Fargate recommendations for services that have accumulated at least 24 hours worth of utilization data in the trailing 14 days. You can access the recommendations through the Compute Optimizer console, AWS Command Line Interface (AWS CLI), and AWS Software Development Kits (AWS SDK).

Compute Optimizer generates recommendations for Amazon ECS services on AWS Fargate

Figure 1. Compute Optimizer generates recommendations for Amazon ECS services on AWS Fargate

An Amazon ECS service orchestrates and manages tasks according to its task definition and service configuration. An Amazon ECS service can have only one task definition that specifies how the associated tasks, such as CPU and memory settings, should be configured to run containers. Thus, Compute Optimizer makes one configuration recommendation per Amazon ECS service on Fargate.

Once you get in the Compute Optimizer console, click ‘ECS services on Fargate’ to see a list of your Amazon ECS services on Fargate. The list prioritizes non-optimized Amazon ECS services on Fargate that have higher current performance risk and cost savings opportunity. A very low performance risk means that the current instance is predicted to always provide enough capability. The higher the performance risk is, the more likely you should consider the recommendation generated by Compute Optimizer. You can see recommended CPU and memory settings, current performance risk, and estimated monthly savings for each Amazon ECS service. The estimated monthly savings is calculated based on AWS Fargate on-demand pricing and the historical utilization of your Amazon ECS services. Based on the current performance risk and cost savings opportunity, you can decide whether you want to take action to optimize your resources or see a detailed view for more information.

Sample view of recommended CPU and memory settings, current performance risk, and estimated monthly savings for each Amazon ECS service

Figure 2. Sample view in Compute Optimizer of recommended CPU and memory settings, current performance risk, and estimated monthly savings for each Amazon ECS service in AWS Fargate.

By clicking on ‘View details’, you’ll get more granularity on the pricing information between current and recommended settings on a single service. There is a column showing what auto scaling configurations the service has. Compute Optimizer won’t generate any recommendation if your service has a step-scaling policy. If there is a target-tracking policy on CPU utilization, then Compute Optimizer will generate only memory size recommendations, and vice versa.

You can also find container-level CPU and memory size recommendations under the detailed view. They are generated, as necessary, to ensure your ECS task definition remains valid when downsizing task sizes.

Sample view of detailed pricing information between current and recommended settings on a single service

Figure 3. Sample view of detailed pricing information between current and recommended settings on a single service

You can also get your Amazon ECS services on Fargate recommendations via the CLI:

$ aws compute-optimizer get-ecs-service-recommendations --service-arn yourservicearn

Replace “yourservicearn” with the service Amazon Resource Name (ARN) of the Amazon ECS service you are interested in. Regardless of your existing ARN format, use the long service ARN in all cases. A long service ARN has the following format: arn:aws:ecs:region:accountId:service/clusterName/serviceName. The return will include both task size and container size recommendations. Here is a sample return:

{
   "ecsServiceRecommendations":[
      {
         "serviceArn":"arn:aws:ecs:us-east-1:123456789012:service/MyCluster/MyService",
         "accountId":"123456789012",
         "utilizationMetrics":[
            {
               "name":"Duration",
               "statistic":"Average",
               "value":11.693175363965134
            },
            {
               "name":"Duration",
               "statistic":"Maximum",
               "value":131.33999633789062
            },
            {
               "name":"Memory",
               "statistic":"Average",
               "value":54.89910979228487
            },
            {
               "name":"Memory",
               "statistic":"Maximum",
               "value":55.0
            },
            {
               "name":"CPU",
               "statistic":"Average",
               "value":54.89910979228487
            },
            {
               "name":"CPU",
               "statistic":"Maximum",
               "value":55.0
            }
         ],
         "lookbackPeriodInDays":14.0,
         "lastRefreshTimestamp":"2022-08-13T21:04:10.299000+00:00",
         "launchType": "FARGATE"
         "finding":"Underprovisioned",
         "findingReasonCodes":[
            "MemoryUnderprovisioned"
         ],
         "currentPerformanceRisk": High, 
         "currentServiceConfiguration": {
            "taskDefinitionArn": "arn:aws:ecs:us-east-1:123456789012:task-definition/MyTaskDefinition"
            "memorySize": 1024,
            "cpuSize": 16,
            "containerConfigurations": [
              {
                "containerName": "myWebService",
                "memorySizeConfiguration": {
                    "memory":512,
                    "memoryReserved": 512
                },
                "cpuSize": 8
              },
              {
                "containerName": "myMonitoringService",
                "memorySizeConfiguration": {
                    "memory":512,
                    "memoryReserved": 512
                },
                "cpuSize": 8
              }
            ],
            "autoScalingConfiguration": "STEP_SCALING"
         },
         "serviceRecommendationOptions":[
            {
               "memorySize":512,
               "cpuSize": 32,
               "savingsOpportunity": {
                   "savingsOpportunityPercentage": 50,
                   "estimatedMonthlySavings": {
                        "currency": "USD",
                        "value": 0.10
                   }
               
               },
               "containerRecommendations: [
                  {
                    "containerName": "myWebService",
                    "memorySizeConfiguration": {
                        "memory":256,
                        "memoryReserved":256
                    },
                    "cpuSize": 8
                },
                {
                    "containerName": "myMonitoringService",
                    "memorySizeConfiguration": {
                        "memory":256,
                        "memoryReserved":256
                    },
                    "cpuSize": 8
                }
               ]
            }
         ],
         "errors" []
      }
   ]
}

Applying the Compute Optimizer recommendations

Here is how you can apply Compute Optimizer recommendations in the Amazon ECS console. First, create a task definition revision with the recommended CPU and memory settings in the Amazon ECS console:

Create a new task definition with your infrastructure requirements

Figure 4. Create a new task definition with your infrastructure requirements

To replace your current task definition, locate the Amazon ECS service in question, click ‘Edit’, and choose your new task definition revision from the ‘Revision’ dropdown list. Click ‘Update’ and Amazon ECS will redeploy your tasks and containers according to new configurations in the revised task definition. You can now enjoy better cost efficiency or performance on your Amazon ECS services on Fargate!

Redeploy your tasks and containers according to the revised task definition

Figure 5. Redeploy your tasks and containers according to the revised task definition

In addition to using the Amazon ECS console, you can also use the following CLI commands to create a new revision of the task definition:

$ aws ecs register-task-definition --family newtaskdefinition --cli-input-json file:///Users/newtaskdefinition_rev1.json

Replace “newtaskdefinition” and “file:///Users/newtaskdefinition_rev1.json” with your current task definition name and your task definition JSON file route, respectively. Make sure you update recommended CPU and memory settings in your task definition JSON file.

Use the following CLI command to replace the current task definition of your service with the new revision of the task definition (replace the red font parts below to your own settings):

$ aws ecs update-service --cluster cluster_name --service my_service_name --task-definition newtaskdefinition:revision

Replace “cluster_name”, “my_service_name”, and “newtaskdefinition:revision” with the name of the cluster associated with the service, the service name, and the task definition and revision number, respectively.

Conclusion

  • This launch only supports Amazon ECS services running on AWS Fargate. For Amazon ECS services that are not running on Fargate, Compute Optimizer cannot generate recommendations.
  • All the tasks under one Amazon ECS service are provisioned according to the task definition attached to the service. A service can only have one task definition. Thus, each Amazon ECS service only gets one task size recommendation, including CPU and memory settings.
  • As with any changes you make to an environment, we strongly advise that you test recommended CPU and memory size configurations before applying them into production.

Start using AWS Compute Optimizer to help identify the optimal CPU and memory configurations for your Amazon ECS services on Fargate. Compute Optimizer supports Amazon ECS services on Fargate in 21 AWS Regions, and these recommendations are available at no additional cost.

To learn more visit: Getting started with AWS Compute Optimizer.

Wenyen Huang

Wenyen Huang

Wenyen is a Senior Product Manager for the AWS Optimizations team. He is passionate about helping customers optimize the value of their AWS spend. Currently, he is working with AWS Compute Optimizer to support new resource types and enhance customization capabilities.