ECS cost optimization: 9 effective ways to reduce ECS costs
Amazon Elastic Container Services (ECS) is one of the simplest yet powerful container orchestration solutions. It allows developers to quickly deploy and manage containers at scale while taking care of aspects such as container lifecycle, automation, storage, networking, etc. But the best part is that AWS provides all these for free.
There are no additional costs for using Amazon ECS. Instead, you only pay for the underlying resources your ECS containers use. You can run ECS containers on EC2, Fargate, or Outpost. Now, containerized applications can make very efficient use of resources in general. Thus, you can save substantial costs if you actively monitor and optimize the resources used by your ECS containers.
This blog post discusses strategies to optimize your containers and the resources used by them to reduce ECS costs. It also covers discounts offered by AWS, which you can apply to save on ECS costs. Let’s start with a brief overview of Amazon ECS pricing models.
Amazon ECS pricing models
The first step towards achieving an efficient ECS pricing structure is to select the most optimum ECS pricing model.
There are no minimum fees, upfront, or additional costs for using ECS, except for the cost of resources used. However, there are two primary charge models for ECS based on the compute platform you choose to run your containers on.
AWS Fargate launch type is the simplest– you define the resources, and it will launch the containers for you. However, it has a one-minute minimum charge for each vCPU and GB of memory your containers request. The billing starts when your container image is pulled until it shuts down, rounded up to the nearest second.
The EC2 launch type is cheaper than Fargate, but the instances are of fixed sizes, and you are responsible for managing the resources. With EC2, you pay for the instances and EBS volumes you select to run your ECS containers. For a detailed comparison, refer to our blog post on Fargate vs. EC2 pricing.
Moreover, you can also host ECS services on AWS Outposts or ECS Anywhere if your container workloads require keeping data or processing it on-premise.
So which pricing model is the best? Check out our blog on Amazon ECS pricing models. It’s a short blog to help you choose the best model according to your specific use cases. You can also request a free consultation with our experts to help estimate your project costs!
3 AWS discounts to save on ECS costs
Once you have figured out which compute platform you want to run your containers on, you can plan on leveraging AWS discounts to cut ECS costs significantly, as discussed below.
EC2 Spot Instances
If you are running your container workloads on EC2, Spot Instances are an excellent way to cut costs. EC2 Spot Instances lets you use the excess compute capacity in the AWS cloud at a whooping discount of 90% compared to on-demand pricing. Then, when AWS needs the capacity back or the spot prices exceed your maximum price, it gives you a two-minute notice to stop, hibernate, or terminate the Spot Instances.
Spot Instances can offer scale and significant cost savings for hyper-scale workloads. But it may not be suitable for all workloads as AWS can interrupt the instances anytime. Moreover, the spot prices fluctuate depending on the demand and supply of Spot Instances. Thus, it can be ideal for fault-tolerant, flexible workloads.
DataFarming, an Australian precision agriculture company, achieved 70% cost savings with EC2 Spot Instances compared to on-demand pricing. It started using Spot Instances to run processes for its containerized environments and could even scale up efficiently when an influx of orders came in.
Mixing Pricing Models: You can further optimize the cost of your workloads with performance by mixing up or combining different EC2 pricing models. For instance, running on-demand instances for critical management workloads simultaneously with spot instances for fault-tolerant workloads.
Druva, a cloud-based data protection company, used EC2 Spot Instances with ECS to decrease costs as it expanded. The company shifted most workloads to Spot Instances and deployed on Reserved Instances when Spot Instances became unavailable. As a result, it saved 20-25% on monthly compute costs with nearly 99.5% uptime.
Fargate Spot
Fargate Spot can help you save up to 70% of the on-demand Fargate pricing and follows the similar concept of Spot Instances. You can run ECS workloads on Fargate Spot when its excess capacity is available. And when AWS wants the capacity back, Fargate Spot will scale down after a two-minute warning. As a result, it can be ideal for running fault-tolerant workloads, parallelizable tasks, and websites and APIs that require high availability.
To optimize your applications for performance in a cost-efficient manner, you can configure a minimum number of tasks to run at all times on Fargate and then add flexible tasks on Fargate Spot. You can use the Fargate Spot capacity provider to run such workloads.
Check Point Technologies, a leading cybersecurity solutions provider, saved substantial costs using Fargate Spot with Fargate and ECS tasks. Its SRE team designed a strategy to deploy Fargate Spot tasks without creating downtime, track task terminations, and maintain reliability. Eventually, Check Point ran its full compliance product suite on Fargate Spot and reduced container costs by 58%.
AWS Savings Plans
It offers significant discounts in exchange for committing to a specific amount of compute usage for one year or three years. AWS Savings Plans come in two types– Compute, and EC2 Instance Savings plans.
Compute Savings Plans are eligible for both Fargate and EC2, applying to resource usage regardless of the instance size, family, region, OS, AZ, or tenancy. It can help save up to 50% costs with a flexible pricing model. The discounts can also vary depending on whether you pay the total amount or part upfront.
Simform recently helped an online automotive information platform achieve cost optimization using AWS Savings Plans and Fargate Spot. Initially, the company saved nearly 30% of costs with Fargate Spot. And later, the company started using Savings Plans for further cost optimization and not to be bound to a particular instance type or AWS region. As a result, it saved a hundred thousand dollars in less than a year.
EC2 Instance Savings Plans offer better discounts but are less flexible. Fargate customers cannot use these plans, and you will be locked into a specific EC2 Instance family and region. To choose the right Savings Plan, you can use AWS Cost Explorer, which analyzes your historical usage and suggests plans that may work for you.
6 container optimization techniques to reduce ECS costs
Another great way of lowering ECS costs is to optimize the resources used by your ECS containers. Below we have discussed a few strategies to help you monitor and ensure your containers are using resources efficiently.
Cost Explorer
As a first step to cost optimization, AWS Cost Explorer helps you take inventory of your historical or current utilization of resources. And it gives recommendations based on usage, allowing you to choose the right pricing models.
For instance, Airbnb used the AWS Cost Explorer early in its journey to visualize cost allocation. It helped understand and manage its AWS costs and usage over time. Later, the company used similar solutions by AWS and adopted Savings Plans to save on EC2 costs.
You can also use reports from the Cost Explorer to stop EC2 instances that are idle or downsize/right-size instances for efficiency. In addition, it is an excellent tool for tracking running hours and costs for ECS and Fargate.
ECS Auto Scaling
AWS’s Auto Scaling feature for ECS automatically increases or decreases the capacity for ECS containers. It is triggered by Amazon CloudWatch metrics that are available for ECS containers, such as memory usage and CPU. You can also use the metrics to add or remove tasks when the load decreases while handling large volumes of incoming requests. As a result, it ensures that cluster services are not scaling unnecessarily and help save costs.
Fine-tuning auto scaling: It is essential to learn the baseline performance of your applications and then measure their performance under load. Establishing such a performance profile helps fine-tune auto scaling configurations for ECS and Fargate.
Types of scaling: ECS auto scaling uses different scaling strategies, such as:
- Target tracking
It adds or removes number of tasks that an ECS service runs based on a specific metric or target value. For example, you can set an average target CPU utilization of 50% across a group of ECS tasks. When CPU utilization increases highly, add capacity and remove capacity when the utilization gets too low.
- Step scaling
It adjusts capacity by dynamic amounts (known as step adjustments) based on the size of a metric or alarm breach.
- Scheduled scaling
It adjusts capacity and increases/decreases number of tasks based on a schedule. For instance, you can schedule ECS instances to shut down during off business hours and weekends for efficient resource usage. Another way is to automate batch scheduling. For example, you can schedule instances to run according to the number of jobs that need to run on them.
Ula, a B2B e-commerce marketplace app for MSMEs in Indonesia, uses ECS for automated container orchestration at any scale. It saves up to 70% on infrastructure costs with ECS plus Spot strategy to provide affordable services. However, Ula also maintains 99% and higher uptime. It uses AWS Auto Scaling to scale resources on demand and deploys EC2 Reserved Instances for backup when Spot Instances are terminated.
Instance scheduling
It helps you control the use of AWS resources by configuring start and stop schedules for EC2 instances. Thus, the Instance Scheduler on AWS can reduce costs by optimizing the use of resources.
For example, you can use it to shut instances of your production environments during off-business hours. It is also ideal for lower-level environments, including test and engineering environments. As for ECS and Fargate services, you can leverage the schedule scaling configuration discussed above.
Right-sizing containers
Another great strategy to optimize ECS costs is to right-size your containers and assign them to the appropriate resources they require to handle their workloads. Again, auditing your containers’ usage is essential as you define the resources for Fargate and choose the instance size of EC2.
Alert Logic, a managed detection and response platform for cybersecurity, used several optimization measures in addition to Savings Plans and Cost Explorer to reduce costs. For instance, it rightsized EC2 instances and parked resources when not used. To further optimize AWS resource consumption, the company resized its ECS clusters. As a result, it could achieve 28% savings with various optimization measures.
Too often, applications are defined with arbitrary configurations for ECS tasks and never revisited. It results in overprovisioning resources for the task and unnecessary spending on wasted resources. Moreover, underprovisioning can lead to throttling of resources and hinders the applications’ performance. Right-sizing is crucial to conserving cloud resources and striking a balance between cost and performance.
For more such best practices that even AWS won’t tell you, refer to our blog on cloud cost optimization. You can also take the help of Simform engineers to optimize your costs. We have helped countless clients do so and would love to help you save some dollars.
Tagging ECS elements
Tagging is a great tool to understand how your business uses resources for containerized applications. You can tag various ECS elements such as tasks, task definitions, clusters, and services. It helps you find orphaned resources that you may not have known about and quietly drives up costs. Other benefits of resource tagging that help optimize ECS costs indirectly include:
- Improved visibility into workloads
- Better allocation of resources and costs
- Easy search and identification of containerized applications and their resources
- Helpful in implementing programmatic infrastructure management and granular resource-level permissions
- Better utilization of Cost Explorer
- Allows organizing of ECS resources spread across different teams, business units, products, and environments
Multiple load balancer target groups
ECS’s feature of Multiple Load Balancer Target Groups is also a great way to optimize containers and reduce costs. It allows you to attach a single ECS service to multiple target groups, consolidating similar or smaller services into one container. As a result, it simplifies infrastructure code, increases the manageability of ECS services, and reduces costs.
Moreover, you need not maintain multiple ECS services to serve traffic from both internal and external load balancers. To learn more, refer to this article which talks about the approach in detail.
Conclusion
To successfully optimize ECS costs, reviewing each method discussed above and determining which suits your specific workloads is essential. However, these techniques are not a one-size-fits-all approach. Instead, the key is to mix them up or combine them with other cost-cutting methods for best results.
Our experts have developed this guide after extensive experience working with AWS services and closely understand its costs. Simform is an Advanced AWS Consulting Partner helping businesses make informed tech decisions to deliver performant applications with real cost savings. Request a free consultation today to estimate costs for your project!