ArticlesTechnology

Cost of Serverless: AWS vs. Azure

5 Mins read
Serverless Cost

Serverless architecture lets you run code without setting up or managing server infrastructure. Cloud-based platforms such as Amazon Lambda and Azure Functions provide a serverless environment in which you provide a “serverless function” with your code, and the service takes care of everything else. In serverless computing, you pay only when your code runs, which can reduce costs in many use cases.

Serverless applications scale automatically based on actual computing needs, with no need for configuration or manual intervention. This is in contrast to traditional cloud computing services like Amazon EC2, in which automated scalability is possible, but is complex to manage and is limited to the level of a single compute instance. In a serverless environment, the infrastructure scales up or down to the precise level of computing resources required by your functions.

One of the main benefits of serverless is the potential for cost reduction. But can serverless really save you money, and how much? Let’s find out how the two biggest serverless providers compare.

AWS Serverless Cost

AWS Lambda

AWS Lambda lets you run code for various applications and backend services. Once you upload your code, Lambda automatically runs and scales your code to ensure high availability. Lambda does not charge you for running the code. Instead, you are billed only for the consumed compute time.

AWS Lambda basic price

At the time of this writing, the basic price for AWS Lambda, in the US East region, with x86 processor, is:

  • $0.0000166667 per GB-second of function invocation.
  • $0.20 per 1 million requests.
  • Starting from $0.0000000021 per ms for 128 MB RAM up to $0.0000001667 per ms for 10240 MB RAM.

AWS Lambda cost factors

Lambda charges for the number of requests for functions and code execution time. Each time Lambda starts executing in response to an invoke call or event notification, it registers a request. The service charges you for the total number of requests across all functions.

Lambda calculates the duration from when the code starts executing and until it returns or terminates, rounding up to the nearest 1 ms. The price varies according to the amount of memory allocated to the function.

AWS Lambda discounts

AWS provides several options for cost optimization in its serverless offering. One example is Compute Savings Plans for Lambda, a pricing model that provides low prices on various services, including AWS Lambda and AWS Fargate. It offers up to 17% off the on-demand Lambda price in exchange for a 1-year or 3-year term commitment. During this time, you commit to a consistent amount of usage measured in $/hour.

AWS Fargate

AWS Fargate lets you use Amazon Elastic Container Service (Amazon ECS) to run containers through a serverless model. It does not charge any upfront costs, allowing you to pay only for the resources you actually use.

AWS Fargate costs

Fargate lets you pay for actual usage of various resources, including vCPU, storage, operating systems, and memory consumed by any containerized application that runs on ECS or Amazon Elastic Kubernetes Service (EKS).

AWS Fargate calculates pricing according to the specific resources consumed. It starts when you download a container image and ends when your Amazon EKS Pod or Amazon ECS Task terminates. Fargate rounders these times up to the nearest second.

Azure Serverless Cost

Azure Functions

Azure Functions is a serverless computing platform provided by the Microsoft Azure cloud. The service has three pricing plans:

  • Consumption plan—Azure provides all the compute resources you need, and you only pay for the time your code runs. However, if application loads suddenly increase, you might experience “cold starts” until new serverless instances are started.
  • Premium Plan—to avoid cold starts, Azure initially warms up some instances that are always online and ready to respond immediately. When the function runs, Azure adds more compute resources if needed. Note that you pay for pre-warmed instances even if they are not used.
  • App service plans—execute functions via the Azure App Service. If you use App Service for other applications, you can run functions on the same plan at no additional cost.

Basic price in the consumption plan

At the time of this writing, the basic price for Azure Functions in the East US region is:

  • $0.000016/GB-second for function execution time, with a free grant of 400,000 GB-seconds
  • $0.20 per million executions, with a free grant of 1 million executions

Interestingly, the price per invocation and price per million requests is identical to that of AWS Lambda for the same region. However, in reality, costs will be different due to nuances of the Azure Premium pricing model vs. Amazon’s pricing options.

Azure Container Instances

Containers are becoming the preferred way to package, deploy, and manage cloud applications. Azure Container Instances provides the fastest and easiest way to run containers on Azure without having to manage virtual machines or use higher-level services.

Azure Container Instances are billed at the “Container Group” level. A vCPU/memory resource allocation can be used by a single container or split across multiple containers. A container group is a co-scheduled container that shares the same network and node lifecycle.

Pricing depends on the number of vCPUs and GB of memory requested in the container group. You are charged for vCPU requests to your container group based on instance duration rounded to the nearest whole number of seconds.

During the container group duration (in seconds), requests from the container group are also billed to the nearest GB and rounded up to the nearest tenth.

Serverless Cost Optimization

Here are a few tips that can help you push costs even lower on AWS and Azure.

Cloud Cost Calculators

There are several AWS pricing calculators and similar options for Azure. These are web-based planning tools you can use to generate quotes for serverless use cases. You can use pricing calculators to model a solution, research the price of a service, and view the calculations behind a quote before building the solution.

When working with AWS and Azure, you can use a calculator to plan your spending approach, identify cost savings opportunities, and make informed decisions about your serverless strategy.

Choose the Right Cost Model

AWS and Azure offer different cost models for serverless services, including on demand (pay-as-you-go), provisioned throughput, and provisioned IOPS. You can use these pricing models to reduce costs and optimize performance, but you must first understand your usage patterns. Based on historical trends of your applications, select the pricing model that optimizes cost while providing the required level of performance.

Cost Analysis

Serverless architecture automatically allocates and deploys additional servers as needed. While letting a provider manage this complexity on your behalf offers many benefits, it can also accumulate unexpected or unpredicted high costs. You can avoid an inflated infrastructure bill by monitoring your AWS Lambda and Azure Functions.

In AWS, services issuing many triggers lead to many functions’ invocations. As a result, it increases compute usage and your infrastructure bill. You can use AWS CloudWatch to monitor Lambda functions, predict traffic levels, and react to cost-incurring events.

Azure Functions offers two metrics you can monitor—Total Executions and Execution Time. You can use the Azure Cost Analysis tool to view billing data at a per-day granularity and predict future costs according to short trials before deploying software to production.

Conclusion

In this article, I described the pricing model of serverless in the AWS and Azure ecosystems, and offered several best practices that can help you optimize costs on both platforms:

  • Cloud cost calculators—use a calculator to estimate your costs for different scenarios.
  • Choose the right cost model—gain an understanding of your usage and choose the most appropriate option, for example, on-demand vs. IOPS-based pricing.
  • Cost analysis—analyze your bill and derive insights from your actual serverless usage.

I hope this will be useful as you find the most cost-effective way to deploy your serverless application.

Author Bio: Gilad David Maayan
   
Gilad David Maayan is a technology writer who has worked with over 150 technology companies including SAP, Imperva, Samsung NEXT, NetApp and Check Point, producing technical and thought leadership content that elucidates technical solutions for developers and IT leadership. Today he heads Agile SEO, the leading marketing agency in the technology industry. LinkedIn: https://www.linkedin.com/in/giladdavidmaayan/

Read Next: Cloud Native Disaster Recovery: Technologies and Best Practices

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 56 = 66