[ARTICLE]

Take Advantage of AWS Fargate Pricing

AWS Fargate is a serverless compute engine for containers that work with Amazon Elastic Container Service (ECS). It is also available in a subset of regions for using Amazon Elastic Kubernetes Service (EKS). Fargate removes the need to provision and manage servers (that is the serverless part, AWS deals with that for you), and the Fargate pricing model lets you specify and pay for resources per application.

Fargate launches and scales the compute resources to match your resource specifications for each container closely. Because Fargate manages the compute aspects for you on a per-container basis, there is no longer a need to pick the right instance size and manage cluster scaling. It also eliminates over-provisioning either due to choosing oversized instances or by having idle instances on hand.  

AWS Fargate Pricing

AWS Fargate pricing is calculated based on the time of use of the resources actually used, specifically vCPU and memory.  Costs are calculated on resources used right from when you start to download a container image until the point when the Amazon ECS Task or Amazon EKS Pod terminates.  Timing is rounded up to the nearest second.

Fargate Pricing Options

If you have worked with EC2 instance pricing before, how Fargate pricing works will feel familiar. There are no upfront payments for Fargate, and you are only charged for the resources you actually use. There is the default, on-demand pricing, and there are Spot and Compute Savings Plan pricing options. If your application is tolerant of being interrupted and restarted, the Fargate Spot option can let you realize up to a 70% discount compared to on-demand prices. If you can commit to spending a certain amount on Fargate over a certain time period to run persistent workloads,  the Compute Savings Plan can let you realize up to a 50% discount compared to on-demand prices. Note that this commitment uses a specific amount of compute (dollar amount per hour) for a one or three-year term.

Tuning Fargate Pricing 

Even though you no longer need to worry about specifying the number of instances you are running, it is possible to optimize cost by looking closely at vCPU and memory resource requests for the Task or Pod. These parameters are pulled from container resource requirements, so if you are overly generous with your resource allocation there, you may still be paying more than you need to.  The two dimensions are independently configurable, as you can see in the supported configuration table below.  Monitoring your application in production can provide you the insight to adjust resource requirements appropriately and then consider Spot or Savings Plan options to save even more on your Fargate pricing. There is a simple tool consisting of a  CloudWatch Dashboard template (here on GitHub) that can help you with right-sizing when used with AWS CloudWatch Container Insights. Do read the section on CloudWatch “gotchas” below first, though.

Supported Fargate Configuration Options

AWS Fargate Pricing Gotchas

As often happens with public cloud services, sometimes you end up paying for extras that you may not have factored into your overall cost for running your apps.  Data transfer can be one gotcha as AWS charges minimally for most storage services when the data is at rest.  Moving data, data transfer can be pricey, and if your Fargate Task or Pod moves a lot of data, this could add substantially to your overall operations cost.  You can check out AWS data transfer rates to get a sense of your potential costs and options.

Also, if your app uses other AWS Services (e.g., CloudWatch for general logging or Container Insights), you will get a bill for your CloudWatch service use as well.  One way to get an estimate for your overall Fargate costs is the AWS Pricing Calculator.  

Conclusion

Fargate has the potential to simplify your operations by eliminating instance and cluster management and can realize substantial savings, especially if you take advantage of Fargate pricing discounts like Spot pricing and Comput Savings Plan options.  Rightsizing your container resource requests and limits can further reduce costs.  Do pay attention to interactions with other AWS services and consider data transfer rates, as these can contribute to the overall cost associated with running AWS Fargate.