AWS Lambda Pricing Vs. EC2

 

The pay-as-you-go principle is used by EC2 and Lambda services as well. Yet, there are a lot of differences between lambda and EC2 pricing model.

  • EC2 Pricing Model:

It charges for every running AWS EC2 instance even when the app or function is not under execution.

Pricing per hour is based on the memory amount, performance of the video card, performance of the CPU, and the capacity of the storage which is utilized by EC2 instances.

It would be better and cost-efficient for you to rely on AWS EC2 instances in case you’d like to keep your app or function available at all times because it having a great number of regular requests.

 

  • Lambda Pricing Model:

 

It charges for a number of executions for apps and for the time it takes to get each execution finished.

Pricing for every running second of a particular app is based on the amount of provided memory for a specific app which is amounted at $0.00001667 for every single Gigabyte-second.

The execution time for the app is counted from the app’s beginning to the result returning or to the after timeout stopping.

Time will get a round up to the closest multiple of 100ms.

At the time that you require to have on-demand availability, the price for using Lambda for running functions or apps might be considered as a best option.

 

EC2 is a service which reflects an IaaS and provides the user with the ability to do the following:

– Getting EC2 instances running as VMs

– Running custom applications
– Configuring environments

Lambda is the implementation of FaaS provided by Amazon which gives users the ability to start running their app with no need to think about the underlying infrastructure.

In case there will be a lot of idle time of your app on an EC2 instance which keeps on running, you should think of jumping to Lambda which does not charge you for idle time in the case that no requests are made for running the app. While, in the case that a great number of regular requests are made to run the app, it would be more suitable for you to deploy your app on a continuously running EC2 instance.

With the utilization of EC2 it will come as a best choice for running the following:

– Long-running apps

– High-performance apps

– Apps that can’t undergo a delay at their start time

 

EC2 vs Lambda in Performance and Availability

EC2:

Upon starting an EC2 instance, it will keep running up till you bring it to a stop manually or get a shutdown task scheduled for it. As soon as an EC2 instance runs, an application will get executed directly on it. Multiple apps can be run at once if the instance’s performance allows this to occur. EC2 instances are a great solution for apps that need to keep running regularly the whole day.

 

Lambda:

Lambda functions will be available at all times without being run all the time. A Lambda function will be inactive by default, and it will be started as soon as a trigger linked to an event gets activated. Maximum running time for a Lambda function is 900 seconds, which means that the execution of a long-running app in Lambda is not preferred in such cases.

 

For the sake of completely understanding the way EC2 and Lambda services differ in their pricing and cost, we will go through a few examples:  

  1. Example One:

An app having 5,000 hits every day and every execution taking 100 MS with 512MB.

Lambda Function Cost= $0.16.

Also, having similar requirements, we may choose the EC2 Instance of “t2.nano”.

EC2 Instance Cost= $4.25.

Hence, Lambda cost being $0.16 is merely 4% of the price of EC2 which is $4.25.

  1. Example Two:

An app with many hits, about 5,000,000 every month, and every execution taking 200 MS with 1GB of Memory.

Lambda Cost= $17.67.

 

Yet, with EC2, for the same requirements we will need the “t3.micros” EC2 Instance for handling such a load.

EC2 Instance Cost= $7.62.

Hence, it is obvious that in such a case, having an EC2 Instance is going to be a less expensive solution than that of using Lambda, because of to the greater requirements for number of requests, memory and execution time.

  1. Example Three:

Multiple EC2 instances are required for the sake of handling the available requests.

In such a case, EC2 is going to be more expensive for 2 major reasons.

– An Application Load Balancer is required for the sake of handling the load balancing between those instances which is going to cost additional expenses.

– EC2 is going to start eating up a bit of the memory that’s getting allocated and traffic won’t get evenly distributed at all times, which will require extra EC2 instances than what was expected.

On the other hand, Lambda is capable of handling the load balancing internally which will result in no additional cost whatsoever as scaling takes place.

Create an application

EC2 lightsail create a disk

AWS EC2 Pricing Calculator


AUTHOR